getline を使用してファイルから行を読み込んでから、各行を表示しようとしています。ただし、出力はありません。入力ファイルは lorem ipsum ダミー テキストで、各文に改行があります。これが私のコードです:
#include <vector>
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
int main() {
string line;
vector<string> theText;
int i = 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] = "";
i += 2;
}
//cout << theText[0] << endl;
for (auto it = theText.begin(); it != theText.end() && !it->empty(); ++it)
cout << *it << endl;
}
return (0);
}