help pls as soon as possible

hi guys, so i am using this code to write to and read from a txt. file but when i write it shows me only the first word while the rest gone. when i write connected words, without space, it shows the same thing i wrote, pls refer to the code below

// writing on a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void write_txt(char complain[512])
{
ofstream outfile;
outfile.open("Hamzahtrial.txt",ios::trunc |ios::in | ios::out
); //for updating the status
cin>>complain;
cin.ignore();
outfile<<complain<<endl;
outfile.close();
}
void read_txt(string line)
{

ifstream myfile ("hamzahtrial.txt");
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}

else cout << "Unable to open file";
}
void call (long recall)
{
int g;
string line;
char complain[512];
cout<<"pls press 0 or 1";
cin>>g;
if (g == 0)
{
write_txt(complain);

}
// reading a text file
else if (g == 1)
{
read_txt(line);
}
else
cout<<":";
}
int main ()
{
long recall;
call(recall);

system("pause");
return 0;
}
cin>>complain;

This takes input until the first space.
Last edited on
so what should i do my friend ???
i am sorry but i have gone through the link u gave me but i couldnt get it
can u give me more help pls
I don't want to read the code in the original post because I'm lazy and there aren't any code tags so it's hard to read.

But as Moschops said, if you want to read the entire line, you want to use getline, not the >> operator. The >> operator stops at any whitespace.

Example:

1
2
3
4
string foo;
cin >> foo;  // <- bad, stops at whitespace

getline( cin, foo );  // <- good, gets the entire line 
Topic archived. No new replies allowed.