Read each line of text file.

This is a discussion on Read each line of text file. within the C++ Programming forums, part of the General Programming Boards category; I'd like to read a text file and insert each line into an array. How can I accomplish that? Each ...

  1. #1
    Semi n00b Mithoric's Avatar
    Join Date
    Jun 2003
    Posts
    293

    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, 01: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, 11: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, 10:54 AM

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