-1
私は入力ファイルからデータを私のvector<stack<string>>
に取り込もうとしているので、この問題が発生しています。 なぜ最初の行をスキップしますか?
1 D
2 C A
3
4 B E
ここにあなたが持っている、あなたの
while (getline(myfile1, line)) {
ループの前に私のコード
ifstream myfile1;
ifstream myfile2; //take in the input file
string line, filename, _block;
vector<stack<string>> _stack;
stack <string> _elements;
cout << "Please enter name of beginning state" << endl;
cin >> filename;
// -------------------------------------------------------------------
// OPEN FILE AND LOAD VERTICES AND EDGES IN APPROPRIATE VECTOR
// -------------------------------------------------------------------
myfile1.open(filename.c_str());
if (myfile1.is_open())
{
cout << "File found!" << endl;
myfile1 >> line;
while (getline(myfile1, line))
{
int i;
string a;
stringstream ss (line);
ss >> i; // "e"
cout<<"Test stupid: "<< i <<endl;
while(ss >> a)
{
_elements.push(a);
cout <<"Test dump: "<< a <<endl;
}
_stack.push_back(_elements);
//cout <<"Test: "<<_elements.top()<<endl;
num_of_stacks = _stack.size();
num_of_elements = _elements.size();
}
//cout <<"Test: "<<_elements.top()<<endl;
while(!_elements.empty())
{
string w = _elements.top();
cout <<"Test1: "<< w <<endl;
_elements.pop();
}
cout <<"Test2: "<<num_of_stacks<<endl;
cout <<"Test3: "<<num_of_elements<<endl;
}
デバッガでコードを実行したとき、どのような観測をしましたか? –
'myfile >> line'とは何と思いますか? – Barmar
これは最初の行をスキップしていないので、最初の行の最初の行をスキップしているだけです。 – Barmar