AFAIK, after upgrading to MinGW 4.4.* some time ago all of my literally written strings (like "i'm the string"
) are treated as of the type std::string
. Is there any command line option to make MinGW treat them 开发者_运维百科as const char*
as it was before?
Strings are per default char *
/ char[]
in C / C++, only if you explicit say its a std::string
you'll get those.
Example:
std::cout << "first:\t" << typeid("aa").name() << std::endl;
std::cout << "second:\t" << typeid(std::string("a")).name() << std::endl;
Output:
first: A3_c
second: Ss
Result:
- first: a
char
array with length of 3 (= 2 chars + end) - second: is a
std::string
As you can see, if you write "abc"
you wont get a std::string
.
But: if you write std::string str = "abc"
you get a std::string
because the asignment operator (=
) is used: string& operator= (const char* s)
精彩评论