Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ File Input to Vector

Name: foreach(nigger in Africa) 2011-12-15 1:12

Well /prog/ I'm trying to read a text file line-by-line into a vector. Is there some sort of inherent vector size limitation I don't know about?

Protip: The file has 23,000 lines. :S

(I've tested it by trying to output the first 1 or 2 vector elements after the loop, but shit just breaks because there's nothing in it??)

Name: Anonymous 2011-12-15 15:32

>>9

    string line;
    vector<string> lines;

    ifstream myFile; //Set vector elements to lines from text file
    myFile.open("ex100926.txt"); //Open txt file
    while (getline(myFile, line))
    {
        lines.push_back(line);
    }
    //Close txt file
    myFile.close(); //Close txt file

    cout<<lines.at(0)<<endl;


This gives me a vector error, because apparently the lines from the text file aren't being read or put into the vector?

I basically have a 100% identical code for another program, which places each string into an array rather than a vector, and that one works 100% fine. (and yes, the file is there and has text in it)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List