I wanted to declare an array with a pointer in character type, and the length of the array can be determined by my input string.
I wrote it in this way:
char *s;
cout << "Enter a string: " << endl;
cin >> s;
I expected that I can initialize the string by the cin operation, but an error showed up when compiling. The error is about "invalid operands to binary expression".
I'm not sure why the lines I wrote was wrong.
I though not only the built in string class is used for declaring an array.
Isn't the string data type in C++ the same as "a character array"?
Isn't the line char *s means the pointer s points to an character array (or string)?
Thank you!
std::string s; std::cin >> s;?char* s;declaressas a pointer, but it does not makespoint at anything. If you want to makespoint at something you have to write the code for that, i.e.s = ....stringis not the same as a character array. And of coursesis not a character array either, it's a pointer, String, array, pointer, all these things are different.