This is a simple program to write to a file, it gets input from the cin command. how can i make the char variable hold a full sentence?
-----------------------------------------------------------------------------------------------------------------
this is the fix
-----------------------------------------------------------------------------------------------------------------
I used a string to hold the sentence and then used the getline command to find the whole thing since just using cin for it will stop after the first word/blankspace.
#include <iostream>
#include <fstream>
usingnamespace std;
int main () {
ofstream myfile ("example.txt");
if (myfile.is_open())
{
myfile << "This is a line.\n";
myfile << "This is another line.\n";
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
i need to use it because I read that it can hold more info, such as a sentence which is what i need. i have fixed the cin problem by using the command wcin instead but that takes the sentence and makes it a number.