百科问答小站 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++循环里面定义重名为什么不报错? 
  如何格式化代码能够将类成员/函数的名字对齐? 
  掌握很多门计算机语言的人不会记串吗? 
  C++工程中的目录有何意义? 
  C++在面向对象编程中,非虚继承和非虚析构函数的存在是为了解决什么问题? 能否都用虚继承和虚析构函数? 
  C语言里a>b?a<c?a:b:c;这个怎么该判断? 
  快奔四的人了,开始学C++,是否太迟了? 
  cygwin和mingw选哪个? 
  在编程语言中,循环语句为何选择 while 而不是 when 作为关键词? 
  在C#中,如何实现跟native dll 中途的线程间通信? 

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





© 2025-03-31 - tinynew.org. All Rights Reserved.
© 2025-03-31 - tinynew.org. 保留所有权利