有一个非常小的问题。这是我为练习而尝试编写的指针程序,但我在 Visual C++ 中遇到错误。
#include "stdafx.h"
#include "iostream"
#include "string"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char *p = "School";
char c;
c = ++*p++;
cout << c << ", " << p << endl;
cout << p << ", " << ++*p-- << ", " << ++p*++; //Error C2059: syntax error : ';'
return 0;
}
也许这是一个非常愚蠢的问题,但我似乎无法理解它。
最佳答案
问题大概是这样的:
++p*++
在最后cout
.看起来你切换了 p
和 *
.
现在我们已经把它放在一边了,在同一行中使用多个具有副作用的表达式会带来麻烦。你想用这个做什么?
c = <i><b>++*p++</b></i>;
还是这个?
cout << p << ", " << <i><b>++<em>p--</em></b></i><em> << ", " << <i><b>++p</b></i></em><i><b>++</b></i>; //Error C2059: syntax error : ';'
评估这些语句的顺序未定义。
关于c++ - C2059 : syntax e r r o r : ';' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9395148/