c++ - How to get cursor to next line after using ">>" operator when reading from file -


i trying read information .txt file looks shown below.to read first 2 lines of integers use ">>" operator read them array. problem want read next line(in entirety) string can convert stream , parse it, when try use getline doesn't read string got me thinking cursor hasn't moved next line , wondering how or other method serve save purpose. structure of txt file below:

2  10 10 10 10 10 10 20 20 20 15 15 15 15 15 15 15 20 30 20 15 15 10 10 10 765def 01:01:05:59 enter 17 abc123 01:01:06:01 enter 17 765def 01:01:07:00 exit 95 abc123 01:01:08:03 exit 95 

my code show below:

#include<iostream> #include<fstream> #include<string> #include <sstream> using namespace std;    int main() {     int arr[24];     int milemarker;     int numberofcases;       ifstream file;     file.open("input.txt");     file >> numberofcases;      (int = 0; < 24; i++)     {         file >> arr[i];     }      (int = 0; < 24; i++)     {          cout << arr[i] << " ";     }     cout << endl;     string line;     getline(file, line);     cout << line;       system("pause"); } 

i think miss getline() call:

#include<iostream> #include<fstream> #include<string> #include <sstream> using namespace std;    int main() {     int arr[24];     int milemarker;     int numberofcases;       ifstream file;     file.open("input.txt");     file >> numberofcases;      (int = 0; < 24; i++)     {         file >> arr[i];     }      (int = 0; < 24; i++)     {          cout << arr[i] << " ";     }     cout << endl;     string line;     getline(file, line);     getline(file, line);     cout << line;       system("pause"); } 

operator >> reads tokens between delimiters. default, space , new line delimiters. after last operator >> call in first loop, still on same line, , first getline() call reads new line character.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -