Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 缺少带+;在弦上_C++ - Fatal编程技术网

C++ 缺少带+;在弦上

C++ 缺少带+;在弦上,c++,C++,基于在编译的代码中看到一个明显的错误,我将其简化为 #include <iostream> #include <string> using namespace std; int main() { const char* p = "The "; string s = string("Bob ") + + "world."; cout << s << endl; } #包括 #包括 使用名称空间std; int main()

基于在编译的代码中看到一个明显的错误,我将其简化为

#include <iostream>
#include <string>
using namespace std;

int main()
{
    const char* p = "The ";
    string s = string("Bob ") + + "world.";
    cout << s << endl;
}
#包括
#包括
使用名称空间std;
int main()
{
const char*p=“The”;
字符串s=字符串(“鲍勃”)++“世界。”;

coutMaximal munch指的是在没有空格的情况下处理一系列标点符号


<>你的代码有空格。语法分析器/词法分析器在中间有空格时不会创建单个令牌,因为语法不允许运算符包含空白。

因为两个代码< > + />代码之间的空间,每个<代码> +>代码>被词法分析器视为一个不同的标记。

你误解了什么?“maximal munch”有-它不会神奇地连接运算符-
++
不会变成
++
。后者应用于
“world.”
,但仅此而已:

string s = string("Bob ") + (+"world.");
想到

int x = +1;

不,
+
+
不同。最后一个子表达式是
+“世界。”
,它是指针上的一元
+
,不起任何作用。

@John没有丢失的操作数,后者
+
应用于
世界“
@LuchianGrigore,一元
+
对字符串文字有什么作用?@MarkRansom文字被提升为指向char的指针,因此它是不可操作的。@John没什么,它是不可操作的。
“世界”
是一个指针,因此对其应用
+
将返回相同的结果。与
+1
相同的和
1
是等效的。我很惊讶编译后的结果!请参见此处: