-
getline question
i'm trying to get a single line of data from a file to be presented on a edit box in Visual C++ 6, and i'm currently strugling with one error that is driving me crazy... already tryed a bunch of stuff but nothing works... please help.
This is my code:
==============================================
BOOL CDTHeaderDlg:OnInitDialog()
{
CDialog::OnInitDialog();
char *buffer=0;
ifstream source("Header.txt");
m_country = source.getline(buffer,30,'\n');
UpdateData(FALSE);
==============================================
This is the error I'm getting:
==============================================
binary '=' no operator defined wich takes a right-hand operator of type 'class istream'(or no acceptable conversion)
==============================================
thanks in advance...
-
One solution is std::getline().
std::string sInput;
std::getline(cin, sInput);
Kuphryn
-
Thanks kuphryn... nevertheless I manage to solve my problem by doing the following code:
==============================================
CDialog::OnInitDialog();
char country[30];
char location[30];
...........
ifstream source("Header.txt");
source.getline (country , 30);
source.getline (location, 30);
...........
m_country = country;
m_location = location;
...............
UpdateData(FALSE);
==============================================
So now, everytime I start my program, it will first populate my variables with values keept on a file called "Header.txt" , that can be updated thru the program like this:
==============================================
UpdateData(TRUE);
ofstream destination("Header.txt")
destination<< m_country<<
endl << m_location<<endl;
==============================================
hope this code can be usefull for someone else.....
Thanks for the help.