0
Please guide
5 Respuestas
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;
}
0
Thanks Mark!
0
But i’m confused why i can’t use this, instead of cout<<!
printf(“\nWelcome”,name);
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.
0
Actually I am teaching a textbook to my students, and there is not use of cin, cout!