Reading A File In As An Argument and Other

Hello,

I have two questions:

One, how do you accept and read a text file called "input.txt" as an argument? I believe the environment being used is a Unix environment.

Two, if the above file contents are:

20
2 20
10 8
4 26
20 7
3 11
13 3
18 5
11 9
1 6
14 10
14 20
8 3
5 26
12 19
6 11
7 14
0 8
19 11
15 9
14 22

How would I write the numbers in, after 20, into two separate arrays. So, in line two, "2" would go into one array while "20" would go into another.
1. http://www.site.uottawa.ca/~lucia/courses/2131-05/labs/Lab3/CommandLineArguments.html

2. For the first line you would read in the single value by itself
lineIn >> X;
for the rest of the lines you would read it in
lineIn >> X; lineIn >> Y;

If you read it in as a string you would break it apart based on where the space is at
There are a couple ways to do that
if (string[i] == " ")
might work and then use string.erase and then convert to a int if that is your desire.
May have taken awhile for me to reply, but thank you. This helped a lot with my next project.
Topic archived. No new replies allowed.