+ 1
Cin.getline and char arrays
Testing with combing two char arrays together. Used this and only prints enter your name. Please help: #include <iostream> using namespace std; int main() { char str[20]; cout << "Enter Your Name::"; // see the use of getline() with array // str also replace the above statement // by cin >> str and see the difference // in output cin.getline(str, 20); cout << "\nYour Name is:: " << str; return 0; }
2 Answers
+ 6
Unfortunately sololearn's code playground doesnt understand what "std::cin::getline()" is and doesn't ask for input, hence an empty input file goes to the server.
One way to counter is to use an alternative method of taking input ( as Ipang pointed out )
Or
Put a deceptive "cin" or "std::getline" somewhere in your program to force code playground to prompt the input dialog box.
Something like this đ
https://code.sololearn.com/cB418fuTukyl/?ref=app
+ 5
std::cin::getline() is not supported in Code Playground. Use C++ std::string instead of char[] and std::getline().
std::string str {};
std::getline(std::cin, str);
std::cout << str << '\n';