Answer this question! | Sololearn: Learn to code for FREE!


Answer this question!

Why it is not taking input? Thanks!

c++ c

7 Answers

New Answer


_ _ We need to take input using cin in cpp. Remove scanf and use cin like cin >> choice;



Simba Then How this code working? C code in cpp?


Use cin instead of scanf


this includes two problems. 1. the (original) code doesn't take inputs in code playground: nothing to add to I Am Groot ! 's answer. but you can use all c functions in c++. it's code-playground-specific. try in other environments. 2. even if it is rewritten as c code like Simba 's answer, it has a complication about how to separate multiple inputs: it's better not to mix scanf() and fgets() since scanf() doesn't read "\n" and fgets() read space as a character. the code below worked on cxxdroid, but with difficulty in controlling multiple inputs: #include <iostream> int main(int argc, char *argv[]) { int digit; char str[50]; scanf("%d",&digit); fgets(str,20,stdin); fgets(str,20,stdin); std::cout <<digit << " "<< str; }



You must take the input using "cin" and the output using "cout". That's the right in cpp