Thread: why wont getline() work?

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    196

    why wont getline() work?

    im working through TICPP one and i cant seem to get getline() to work;

    i am actually having a new problem. ive gotten getline to work. i was just reading from the wrong stream. but now i cant seem to get the output in normal text rather then hex?

    0x22fdb4 is what i get. when i want to output the whole string

    Code:
    #include <iostream>
    #include <string>
    #include <fstream>
    
    using namespace std;
    
    int main(){
        
        string msg = "this is a string";
        ofstream space_fileA ("spaces.txt");
        space_fileA<< msg;
        space_fileA.close(); 
        ifstream space_fileB ("spaces.txt");
        space_fileB>> msg;
        getline(space_fileB, msg);
        
    }
    any help at all is appreciated
    Last edited by lilhawk2892; 03-30-2009 at 09:51 PM.

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    596
    Code:
    #include <iostream>
    #include <string>
    #include <fstream>
    
    using namespace std;
    
    int main(){
        string msg = "this is a string";
        string msg2;
        ofstream space_fileA ("spaces.txt");
        space_fileA<< msg;
        space_fileA.close(); 
        ifstream space_fileB ("spaces.txt");
    //    space_fileB>> msg;
        getline(space_fileB, msg2);   // note: B, not A
        cout << msg2 << endl;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  2. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 04:48 AM
  3. Why won't my OpenGL work?
    By Raigne in forum C++ Programming
    Replies: 7
    Last Post: 11-26-2005, 11:53 AM
  4. Help with getline() and file reading
    By evilkillerfiggi in forum C++ Programming
    Replies: 5
    Last Post: 10-15-2005, 03:49 PM
  5. Developers Wanted
    By Quasicom in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 08-24-2005, 12:46 AM