inputting into a text file...only more complicated

i know that cin will end after the first white space so im supposed to use getline instead, the problem using it like this "myfile << getline (cin, line) "gives me the address (so i messed with pointers for a bit) and some people on the net say you got to myfile getline(myfile, line) i need to review some things all the time im a beginner but this should stillbe easy and im not finding the solution anywhere


#include <iostream>
#include <string>
#include <fstream>

using namespace std;

main ()
{

string line;
string filename;

cout << "enter file name\n";
cin >> filename;
cin >> line;
ofstream myfile;
myfile.open (filename.c_str());

myfile << getline(cin,line);

return 0;
}

i have followed the dev tutorials and buckys great youtube tutorials but im sure some stuff is still very hazy


see what im trying to do...when i suxs this out i might then learn how to take key words out of a sentence so i can quickly get the recipie components by simply writing the method

and a daily diary that records the date and time and allws me to make as many entries a day as i like untill the next day...maybe even password protect them and create a tidy form for it
Instead of this,
myfile << getline(cin,line);

maybe try this:
1
2
    getline(cin,line);
    myfile << line;
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

main ()
{

string line;
string filename;


cout << "enter file name\n";
cin >> filename;
cin >> line;
ofstream myfile;
myfile.open (filename.c_str());


getline(cin,line);
myfile << line;




system ("pause");
return 0;
}


this works XD well done chervil il have you know my file comtained the text I LOVE CHERVIL <3

can you tell me how this works now? forget it chervil youve done enough you beautiful man you
Topic archived. No new replies allowed.