Simple program to read and output

I'm on chapter 2, Thinking C++ - I wanted to challenge myself so I tried to take what I learned thus far (vectors, fstream, iostream) and create a program that reads what the user types in the command prompt and saves it to a file "outputTEST.txt", until semicolon is typed, and then output to the command prompt what was in the file that was just made. The file saves, however it does not cout my file to the command prompt. Can somebody help me with this? Here is my code:

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
#include "stdafx.h"
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	return 0;
}

int main() {
	string a1;
	cout << "Please enter the content to be saved into file: ";
	ofstream myfile;
	myfile.open ("outputTEST.txt");
	while (a1 != ";") {
		getline (cin, a1);
		myfile << a1 << "\n";
	}
	myfile.close();
	vector<string> v;
	ifstream in("outputTEST.txt");
	string line;
	while(getline(in, line)) {
		v.push_back(line);
	}
	for(int i = 0; i < v.size(); i++)
		cout << line << endl;
}
Last edited on
Nevermind, I just figured it out - I had to output v[i] not line:

1
2
	for(int i = 0; i < v.size(); i++)
		cout << v[i] << endl;
Topic archived. No new replies allowed.