Thread: Read each line of text file.

  1. #1

    Read each line of text file.

    I'd like to read a text file and insert each line into an array.
    How can I accomplish that?

    Each line will have an .exe file name on it like this:

    iexplore.exe
    msimn.exe
    msmsgs.exe

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    148
    Read in with getline
    Code:
    #include <string>
    #include <iostream>
    #include <fstream>
    #include <vector>
    using namespace std;
    
    ....
    ifstream file;
    ....
    string line;
    vector<string> vec;
    while(getline(file,string) && !line.empty())
        vec.push_back(line);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help is needed to read text from a file
    By yuzhangoscar in forum C Programming
    Replies: 12
    Last Post: 09-12-2008, 12:10 AM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  3. reading a text file printing line number
    By bazzano in forum C Programming
    Replies: 4
    Last Post: 09-16-2005, 10:31 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM