Trouble understanding the char-type variable
I've been kind of bridging the gap from PHP/Javascript website design to C++, and found a weirdness about the char variable type.
This is what I don't understand. This program fails to compile:
1 2 3 4 5 6
|
int main()
{
char testString="t";
cout << testString << "\n";
return 0;
}
|
with the output:
1 2
|
./stringTest.cpp: In function `int main()`:
./stringTest.cpp:8: error: invalid conversion from `const char*` to `char`
|
Yet the following program compiles and works as expected:
1 2 3 4 5 6 7
|
int main()
{
char testString;
cin >> testString;
cout << testString << "\n";
return 0;
}
|
1 2 3 4 5 6
|
int main()
{
char testString='t';
cout << testString << "\n";
return 0;
}
|
I hope you see now
single-quotes for individual characters, double-quotes for strings?
yes
Topic archived. No new replies allowed.