开发者

How to make MinGW to treat texts like "text" as const char*

开发者 https://www.devze.com 2023-03-21 16:41 出处:网络
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 MinG

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消