Help With Files

How do i input a full sentence into a file? It only stores one word

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
47
48
#include <iostream>
#include <fstream>
#include <cstdlib>
#include<string>

using namespace std;

int main() {

	string txt;

	ofstream outFile("test.doc", ios::out);
	
	cin >> txt;

	outFile << txt;
	outFile.close();

	cout << "Do you want to read the file?" << endl;
	string answer;
	cin >> answer;


	if(answer == "yes" || "ye" || "y"){

		string line;
		ifstream myfile ("test.doc");
		 if (myfile.is_open()) {

			while ( myfile.good() ) {

		getline (myfile,line);

		cout << line << endl;
			}

		myfile.close();

		  }

		  else cout << "Unable to open file"; 


	}

	system("pause");

}
Last edited on
1
2
3
4
5
6
7
ofstream outFile("test.doc", ios::out);
	
//cin >> txt;
std::getline(std::cin, txt);

outFile << txt;
outFile.close();
Thanks alot :D
Topic archived. No new replies allowed.