+ 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; }
2 Answers
+ 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
+ 3
U forgot to include <iostream> which contains cin and cout and other few functions for input/output in the command-line