xcode - C++ program doesn't completely read huge input. Why? -


i want solve programming contest task (c++ xcode) has relatively big input (300 lines). when copying test input console, doesn't read all. have written minimalistic test program read in 300 lines:

#include <iostream>  using namespace std;  int main(int argc, const char * argv[]) {     ios_base::sync_with_stdio(false);      string xxx;     for(int = 0; < 300; i++)         cin >> xxx;     return 0; } 

if execute , copy 340 lines "aaaaaaaaaa" console, doesn't end. if stop debugger, says = 92. if continue, quits. when copy pieces of 50 lines console, quits immeadiately should...

can me this?

ps: inserted 'ios_base::sync_with_stdio(false);', because read spped input up.

i want solve programming contest task (c++ xcode) has relatively big input (300 lines). when copying test input console, doesn't read all

this possible when have more 1 word per line because cin >> xx read words opposed lines.

you need use getline method read lines.

while (getline(cin, xxx)); 

if execute , copy 340 lines "aaaaaaaaaa" console, doesn't end. if stop debugger, says = 92.

yes, same symptom. if had 1 word per line, reach 300 lines, never 340.

here whole code write reference:

#include <iostream>  using namespace std;  int main(int argc, const char * argv[]) {     ios_base::sync_with_stdio(false);      string xxx;     while (getline(cin, xxx))         cout << xxx << endl;     return 0; } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -