This code does not work. But it works in pc. Why? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

This code does not work. But it works in pc. Why?

#include <iostream> #include <sstream> #include <string> using namespace std; int main() { string s; string a; getline(cin,s); istringstream iss(s); do { string subs; iss>>subs; a=subs[0]; subs.erase(subs.begin()); subs=subs+a+"ay"; cout <<subs<<" "; } while(iss); return 0; }

27th Dec 2019, 10:56 AM
Safari Fason
Safari Fason - avatar
12 Answers
+ 1
It works! Thank you a lot!
27th Dec 2019, 12:18 PM
Safari Fason
Safari Fason - avatar
0
remove (do{ ) and (while(iss) ;) and leave what's inside. it should work. //do //{ string subs; iss>>subs; a=subs[0]; subs.erase(subs.begin()); subs=subs+a+"ay"; cout <<subs<<" "; //} while(iss);
27th Dec 2019, 11:45 AM
Bahhaⵣ
Bahhaⵣ - avatar
0
No changes. Message: timeout: the monitored command dumped core
27th Dec 2019, 11:48 AM
Safari Fason
Safari Fason - avatar
0
try what I suggested.
27th Dec 2019, 11:49 AM
Bahhaⵣ
Bahhaⵣ - avatar
0
In this case it outputs only first word from sentence
27th Dec 2019, 11:50 AM
Safari Fason
Safari Fason - avatar
0
oh I only tried it on one word 😅
27th Dec 2019, 11:54 AM
Bahhaⵣ
Bahhaⵣ - avatar
0
)
27th Dec 2019, 11:54 AM
Safari Fason
Safari Fason - avatar
0
try this 😄 int main() { string s; string a; string subs; getline(cin,s); istringstream iss(s); while(iss >> subs){ a=subs[0]; subs.erase(subs.begin()); subs=subs+a+"ay"; cout <<subs<<" "; } return 0; }
27th Dec 2019, 12:09 PM
Bahhaⵣ
Bahhaⵣ - avatar
0
or this if you like to keep do{} while; move string subs to top and add iss >> subs in while() int main() { string s; string a; string subs; getline(cin,s); istringstream iss(s); do { iss>>subs; a=subs[0]; subs.erase(subs.begin()); subs=subs+a+"ay"; cout <<subs<<" "; } while(iss >> subs); return 0; }
27th Dec 2019, 12:13 PM
Bahhaⵣ
Bahhaⵣ - avatar
0
The fact is that here the compiler is arranged differently, but on a PC in its own way. Well, something like that.
28th Dec 2019, 1:55 PM
alexey_51
alexey_51 - avatar
0
May be the compiler is not good enough
28th Dec 2019, 8:14 PM
Cyber Ninja
Cyber Ninja - avatar
0
Cyber Ninja it was not a compiler issue, it was an infinite loop issue.
28th Dec 2019, 8:35 PM
Bahhaⵣ
Bahhaⵣ - avatar