why wont getline() work?

This is a discussion on why wont getline() work? within the C++ Programming forums, part of the General Programming Boards category; im working through TICPP one and i cant seem to get getline() to work; i am actually having a new ...

  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
    595
    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, 03:48 AM
  3. Why won't my OpenGL work?
    By Raigne in forum C++ Programming
    Replies: 7
    Last Post: 11-26-2005, 10: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21