15th Dec 2019, 8:51 AM
Arslan Ali
Arslan Ali - avatar
5 Respostas
0
Hi Zelda X You are trying to store a string (i.e., a word, phase, etc) in a variable that accepts single characters, the char type. To accomplish what you want try this: #include <iostream> using namespace std; int main() { string name; cout << "Enter your Name:"; cin >> name; cout << "\nWelcome, " << name; return 0; }
15th Dec 2019, 12:10 PM
Mark
0
Thanks Mark!
15th Dec 2019, 12:12 PM
Arslan Ali
Arslan Ali - avatar
0
But i’m confused why i can’t use this, instead of cout<<! printf(“\nWelcome”,name);
15th Dec 2019, 12:22 PM
Arslan Ali
Arslan Ali - avatar
0
Hi Zelda X You can, but please notice that printf() and scanf() are function from the C Standard Library "stdio.h" and not from the C++ "iostream". If you want to use printf(), the syntax would be something like: printf("\nWelcome, %s\n", name); But please notice that the type "string" does not exist in C. You should convert the C++ string to a C char array.
15th Dec 2019, 12:27 PM
Mark
0
Actually I am teaching a textbook to my students, and there is not use of cin, cout!
15th Dec 2019, 12:31 PM
Arslan Ali
Arslan Ali - avatar