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; }
12 ответов
+ 1
It works! Thank you a lot!
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);
0
No changes. Message: timeout: the monitored command dumped core
0
try what I suggested.
0
In this case it outputs only first word from sentence
0
oh I only tried it on one word 😅
0
)
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;
}
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;
}
0
The fact is that here the compiler is arranged differently, but on a PC in its own way. Well, something like that.
0
May be the compiler is not good enough
0
Cyber Ninja it was not a compiler issue, it was an infinite loop issue.