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);
ok i got it, it works only when i put it in the main ,int main().
but it doesnt work when i put in a function
do u know why???
i am talking about ur first comment