Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 608001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:25:04+00:00 2026-05-13T17:25:04+00:00

Hi I have a text file containing two arrays and one value(all integers) like

  • 0

Hi I have a text file containing two arrays and one value(all integers)
like this

3 90 22 5 60 33 24

Where the first number stands for how many integers to read in.
I can read in all this in one function.
Do I need several functions to be able to use the different matrices and the first variable?

    ifstream in(SOMEFILE.dat);
    if (!in) {
    cerr << "Cannot open file.\n";
    return -1;}
    in >> VAR;
    A=new int[VAR]; 
    B=new int[VAR];
    for(int i=0 ;i<VAR;i++){
      in >>A[i];
    }
 for(int i=0 ;i<VAR;i++){
      in >>B[i];
    }

       in.close();

Above is the code I have so far and this would work in the main function.
Do I have to write three functions to read this info in so I can use it in my program or is there any way I could for example send in three pointers to a function?

I would like A to be 90 22 5
B to be 60 33 24
And VAR to be 3

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:25:05+00:00Added an answer on May 13, 2026 at 5:25 pm

    Whenever you want to group together data items, use a class or a structure. For example, to pass three integers as x, y and z coordinates,:

    struct Coord {
       int x, y, z;
    };
    

    and then pass the structure to the function:

    void f( Coord & c ) {
    }
    

    The same goes for arrays, but in your case you would make the structure contain pointers.

    Your question actually opens up huge areas of C++ programming that it seems you are not aware of. Some things you should read up on before you go any further:

    • the concept of structures, as outlined above
    • constructors and destructors for structures
    • when and when not to use dynamic memory allocation
    • use of C++ standard library containers like std::vector

    This may seem a lot, but once you have a clear grip on these, you will find C++ programming much, much easier and safer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to filter a text file filter.tmp containing two types of lines, this
I have a plain text file looking like this: some text containing line breaks
I have 1 text file containing Ips .Like this iptextfile.txt 10.0.0.1 192.168.1.1 123.123.123.123 And
I have a text file containing two or more types of lines. I would
I have a text file containing a number of records. Each record is stored
I have a text file containing words separated by newline , like the following
I have a text file containing ~300k rows. Each row has a varying number
I have a text file containing 10 columns of numbers. What I would like
I have a file, called WrongFileTypeDetection.R, containing the following text: # This file is
I have a function that reads a text file containing two lines, it reads

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.