How to read data from stdin, for a given number of test cases in C++ -


this might sound silly, it's first time solving programming contests on line. problem described as:

input: first line indicates number of test cases t.for next 't' lines data entered. 

i've written following program (with correct headers included):

vector<string> read_strings(int t_cases) {     vector<string> ip_vec;     string line, str;     int cnt = 0;      while (cnt != t_cases-1) {         std::getline(std::cin, line);         ++cnt;     }      std::istringstream iss(line);     while (iss >> str) {         ip_vec.push_back(str);     }     return ip_vec; } 

but program gets stuck in input loop. i've tried parse line it's entered putting iss in first while loop. if provide me pointer on how solve problem, able test rest of program.

thanks.

you need add lines vector read. first while loop reading through test cases, not saving them somewhere. next while loop tries reads line, last test case read. try following:

vector<string> ip_vec; string line, str; (int cnt = 0; cnt < t_cases; cnt++) {    std::getline(std::cin, line);    ip_vec.push_back(line); } 

Comments