Read file, then set each line as a string array

Well, I think this is how I will do it:

1. ifstream will declare and open a text file.
2. the console will read each line in the file, and set each line as a value in a single string array.
3. once finished setting the string array, it will put each line into another string (by adding the line from the file after a set beginning string, then it will be closed by a set ending string.)
4. the freshly made string from step 3 will be written to an output ".txt.output" file.
5. Once the console is finished with looping through the file, it will display a "finished" message.
6. The user presses ENTER and the console closes.

Any ideas on how to make this possible in a C++ console?
should get the file open to read
1
2
ifstream infile;
  infile.open ("test.txt", ifstream::in);
Last edited on
I must be feeling pretty generous to do some of your homework. You have to do the rest.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
string arString[3];
	ifstream ifs("test.txt");
	int i =0;
	while(ifs.is_open())
		{
			while(ifs.good())
			{
				getline(ifs,arString[i]);
				cout<<arString[i]<<"\n";
				i++;
			}//end isgood
			
			if(ifs)
			{
				ifs.close();
			}
		}//end isopen
	
	
	cout<< "Finished!" << "\n";

	system("pause");
	return 0;
Topic archived. No new replies allowed.