with char i get this error: .\main.cpp(6) : error C2015: too many characters in constant
+6
A:
A char
only holds one character:
char bar = 'a';
If you want more, use a string constant to initialize a character array:
char foo[] = "This is my thing";
jeffamaphone
2010-04-22 17:32:59
+1
A:
Use a string i.e. array of characters For example char s[] = "Hello";
Naveen
2010-04-22 17:33:21
Or, if you're not planning on modifying the string, a `char *s = "Hello";` will do.
Eclipse
2010-04-22 17:37:38
That uses a deprecated conversion in C++ though, use `const char* s = "Hello";` or preferably `std::string`.
Mark B
2010-04-22 18:30:35
In fact, in C++0x the conversion is not allowed anymore.
Johannes Schaub - litb
2010-04-23 04:02:19
+6
A:
Given the file extension cpp
, I am going to go out on a limb and assume you are using C++. If so, use the string
class to store a string.
Sinan Ünür
2010-04-22 17:34:15
+2
A:
See Compiler Error C2015 for an explanation of the error. MSDN is a great source of knowledge and usually describes the error messages from Visual Studio (as I assume you are using) in more detail.
Martin
2010-04-22 17:35:17