百科问答小站 logo
百科问答小站 font logo



c++初学者有必要深挖这样的问题吗? 第1页

  

user avatar   haozhi-yang-41 网友的相关建议: 
      

不用什么深挖,因为这就是:规定

这是C++03的版本(2.13.4.1):

A string literal is a sequence of characters (as defined in 2.13.2) surrounded by double quotes, optionally beginning with the letter L,asin"..."or L"...". A string literal that does not begin with L is an ordinary string literal, also referred to as a narrow string literal. An ordinary string literal has type “array of n const char” and static storage duration (3.7), where n is the size of the string as defined below, and is initialized with the given characters. A string literal that begins with L, such as L"asdf", is a wide string literal. A wide string literal has type “array of n const wchar_t” and has static storage duration, where n is the size of the string as defined below, and is initialized with the given characters.

至于很多人回答的:严格按照C++语法你的代码会编不过的原因,也已经用黑体给你标了。

其他版本的C++,甚至c的,自己也可以下载个标准文本,然后用“string literal”这个关键字去搜。


btw:

这种东西在我看来不值得花什么精力去深究,因为它本质上就是一个可以让大家更便于编写代码,也让代码更好读的语法糖

毕竟你可以老老实实的写一个字符数组,然后用strcpy初始化。最后等着编译器发现这个变量可以执行编译优化,最终优化成一个指向常量的指针,在结果上是一样的——当然,有没有这么牛X的编译器,倒是个问题。




  

相关话题

  C++ 运动完上一个函数到下一个函数时,上一个函数里的变量值(结构体变量)为什么没保留住,变成零了? 
  3个小时,用 C++ 写不出AVL树,有些迷茫,怎么办? 
  写 C C++ 语言时候,如果每次申请内存就把 Free 内存的代码写上,是否能有效避免内存泄漏? 
  为什么C++里,封装类对象消亡时候,先执行封装类的析构函数,再执行成员对象的析构函数? 
  C++ 几十年来为什么没给 break 语句加上参数? 
  C++可否将父类的对象cast子类,并调用子类的private函数? 
  Android 将来能否实现用 C/C++ 作为开发语言?还是说现在的架构就注定了只适合用 Java? 
  c++ 标准库有哪些api接口设计的不好用? 
  C++ make_tuple返回值类型,会有效率问题吗? 
  为什么游戏引擎大多选择使用 C++ 而不是 C 开发? 

前一个讨论
如果高中生合成了新的化学元素,能被保送清华北大的化学学院么?
下一个讨论
勘探油田的技术难点在哪里?





© 2025-05-28 - tinynew.org. All Rights Reserved.
© 2025-05-28 - tinynew.org. 保留所有权利