+ 3
String and Variables
Hi! I want to ask, my c++ code doesn't work when I want to input string. Here's the code : #include <iostream> #include <string> int main () { string name; int m, s, h; while (option =! 6) { cout << "\nOPTION : \n1. INPUT \n2. NONE \nInput Option : "; cin >> option; if (option==1) { std::string name; std::cout << "Name : "; std::getline(std::cin, name); cout << "your name : " << name; cout << "Math : "; cin >> m; cout << "students name : " << name; cout << "Math : " << m << endl; } } return 0; } I can't input the string, it just jumped directly to variable (I don't know why) can someone please help me how to fix the code so I can input both string and variable correctly. Thank you!
2 odpowiedzi
+ 3
Thank you Solomoni Railoa , let me try it on my compiler.