Loading a vector from a file

Alright i have my program and it loads the vector fine and even puts the vector into a txt file but when it comes to lloading it again im not sure if it works or not

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <string>
#include <fstream>
#include <vector>

using namespace std;

int main()
{
	string input;
	vector<string> test;

	do
	{
		getline(cin,input);                    // Loading the vector with input
		test.push_back(input);
	}
	while ( test.size() < 5 );

	for( int i = 0; i < test.size(); i++)     // Loading the vector to at txt file
	{
		fstream inout;
		inout.open("Vector.txt", ios::app);
		inout << test[i]<< endl;
		inout.close();
	}


		for( int i = 0; i < test.size(); i++)
	{
		string line;
		fstream inout("Vector.txt");            // Loading the vecotr from the txt file
		while( !inout.eof())
		{
			getline(inout,line);
			test.push_back(line);
		}
		inout.close();
	}
			for( int i = 0; i < test.size(); i++)  // Not sure what is happening
	{
		cout << test[i]<<endl;
	
	}
			system("pause");
}
Last edited on
Remove line 29 and test.clear(); before the loop on line33
Thank you works fine now ^^
Topic archived. No new replies allowed.