Input string typed on keyboard and saved to file

I'm trying to write a simple program that will prompt for a string typed in by keyboard and save it to a file. I've tried lots of variations and this is just the latest version. What am I not doing? Would appreciate help for the helpless.

//Prompt for a string input by keyboard and save the string in a file

#include <string
using namespace std;

int main()
string line;
ifstream myfile; ("newtext.txt");
string input = "";
cout << "Input text and press return:\n";
getline(cin, input);
//cout << getline (cin, input);
//cin i;
myfile << getline(cin, input); //error here
return 0;
Wrong type. ifstream --> Input File Stream | ofstream --> Output File Stream

getline(cin, input);
myfile << input;
Last edited on
Topic archived. No new replies allowed.