I've been trying to learn C++ for about a year now and came across this excellent tutorial. I can't leave anything alone so I changed some single quotes to double quotes and have the following code:
#include <iostream>
void printTwice(char phil) {
std::cout << phil << phil << std::endl;
}
int main() {
std::cout << "First line." << std::endl;
printTwice('a');
printTwice("a");
std::cout << "Last line." << std::endl;
return 0;
}
...which gives me (under Fedora 13 GNU/Linux and the latest GCC):
[jw0@localhost ~]$ g++ -o program.exe program.cpp
program.cpp: In function ‘int main()’:
program.cpp:10: error: invalid conversion from ‘const char*’ to ‘char’
program.cpp:10: error: initializing argument 1 of ‘void printTwice(char)’
If I remove printTwice("a") then it works fine. I did some Googling for the differences between const char* and char but I couldn't extrapolate from the various forum posts why single quotes work and double ones don't. I would be really grateful if someone could let me know - I can carry on the tutorial without it but it would be interesting to find out.
Thanks in advance for any help/tips/pointers :)