Thread: getline question

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    47

    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...
    I'm a person with a simple taste...
    I only like the best.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is std::getline().

    std::string sInput;
    std::getline(cin, sInput);

    Kuphryn

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    47
    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.
    I'm a person with a simple taste...
    I only like the best.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question About Getline
    By bengreenwood in forum C++ Programming
    Replies: 2
    Last Post: 04-28-2009, 05:13 PM
  2. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  3. getline question
    By Swaine777 in forum C++ Programming
    Replies: 2
    Last Post: 03-30-2003, 06:17 AM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. getline question
    By Kings in forum C++ Programming
    Replies: 9
    Last Post: 01-20-2003, 01:01 PM