c++ - 'cout' was not declared in this scope error -


i'm trying read in lines file using getline, display each line. however, there no output. input file lorem ipsum dummy text, new lines @ every sentence. here code:

#include <vector> #include <string> #include <fstream> #include <iostream>  using namespace std;  int main() {      string line;     vector<string> thetext;     int = 0;     ifstream infile("input.txt");      if(!infile)         cout << "error: invalid/missing input file." << endl;     else {         while(getline(infile, line)) {             thetext[i] = line;             thetext[i+1] = "";             += 2;         }          //cout << thetext[0] << endl;         (auto = thetext.begin(); != thetext.end() && !it->empty(); ++it)             cout << *it << endl;     }     return (0); } 

vector<string> thetext; ... while(getline(infile, line)) {     thetext[i] = line;     thetext[i+1] = "";     += 2; } 

the first line declares empty vector. add items need call push_back(), not assign indices. assigning indices past end of vector illegal.

while(getline(infile, line)) {     thetext.push_back(line);     thetext.push_back(""); } 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -