+ 2

Please help wity code. Why it doesn't work?

#include <string> using namespace std; int main() { string msg; cin >> msg; if(msg == "Hi"){ cout << "Hello"; } return 0; }

14th Apr 2018, 10:49 AM
Daniel
Daniel - avatar
2 Respuestas
+ 8
#include <iostream> #include <string> using namespace std; int main() { string msg; getline(cin,msg); if(msg == "Hi"){ cout << "Hello"; } return 0; } getline()  function is used to store a stream of characters as entered by the user in the object memory. so to access string element use like above
14th Apr 2018, 10:58 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 3
U forgot to include <iostream> which contains cin and cout and other few functions for input/output in the command-line
14th Apr 2018, 10:59 AM
Hallox
Hallox - avatar