Hey guys.
I'm trying to make a program that reads a string that is entered by a user, and outputs that string to a text file. Everytime I run this code, the text stored in response doesn't get put into the example.txt file that the program creates.
#include <fstream>
#include <cstdlib>
#include <iostream>
usingnamespace std;
int main() {
// Putting response in place of the text also works in this situation.
string response = "spaghetti";
// cout<<"Please enter some text";
// getline(cin, response);
// cout<<"Copying text to file..."<< endl;
ofstream myFile;
myFile.open("example.txt");
// cout<<"Response is " << response <<endl;
myFile <<"SPAGHETTI\n";
myFile.close();
cout<<"Done..." <<endl;
system("PAUSE");
return 0;
}
I have no clue what I am doing wrong. I don't know if it's the IDE I'm using (eclipse), or if I am messing something up somewhere. Can anyone help me out?