Thread: ofstream, ifstream?

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

    ofstream, ifstream?

    Hrmm... is there anyway to print more than just the first word of a text file using ifstream?
    // Kavity

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    use getline()
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    49

    Erm, example?

    Would you be able to give me an example? :\
    // Kavity
    i'm not stupid, just a little short on brains.
    Kav's game!
    Featuring:
    # - Goodguy mc goodguy
    * - Bad guy mc badguy
    $ - Princess Mc Cess
    @ - Mcdonalds Mc chicken! mmmmmm

  4. #4
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Code:
    #include <fstream>
    #include <iostream>
    #include <string>
    
    // ... 
    
    std::ifstream fin("filename.txt", std::ios::in);
    std::string buffer;
    
    while (std::getline(fin, buffer))
        std::cout << buffer << endl;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ofstream... broke as a result of ifstream fix
    By tms43 in forum C++ Programming
    Replies: 3
    Last Post: 11-12-2006, 11:40 AM
  2. Capturing key presses
    By cgod in forum Windows Programming
    Replies: 6
    Last Post: 11-25-2004, 01:10 PM
  3. ofstream and ifstream for searching and writing
    By johnnyd in forum C++ Programming
    Replies: 6
    Last Post: 03-17-2003, 08:34 AM
  4. Replies: 9
    Last Post: 06-06-2002, 07:03 PM
  5. STL to: Cin, Cout, ifstream & ofstream
    By kuphryn in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2001, 09:32 AM