ofstream problems

This is a discussion on ofstream problems within the C++ Programming forums, part of the General Programming Boards category; I am reading a variable through cin and i wish to output it to a file, my beta version works, ...

  1. #1
    Unregistered
    Guest

    ofstream problems

    I am reading a variable through cin and i wish to output it to a file, my beta version works, but it kills the output after the first space...the tutorial here says to use the following code:
    Code:
    string output;
    //use char or string??
    
    yada yada yada
    
    cin.getline(output,'\n');
    and yes i do have a main function and all that good stuff...i followed the example exactly, but during compile, i get this error:
    Could not find a match for 'istream::getline(string,char)' in function main()

    please help me, it would be much appreciated

  2. #2
    Snior Member
    Join Date
    Jan 2002
    Posts
    982
    std::string has its own global getline function, the version you're using works with char arrays. Try something like -

    std::getline(cin,output,'\n');

  3. #3
    Unregistered
    Guest
    thanks!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 03:59 AM
  2. ofstream and ifstream for searching and writing
    By johnnyd in forum C++ Programming
    Replies: 6
    Last Post: 03-17-2003, 08:34 AM
  3. ifstream and fileIn problems
    By jobolikescake in forum C++ Programming
    Replies: 8
    Last Post: 10-26-2002, 04:00 PM
  4. Replies: 9
    Last Post: 06-06-2002, 08:03 PM
  5. Removing *Unchanged* Output File (ofstream) :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 01-05-2002, 07:47 PM

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