#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
int main() {
string str("hello world!");
for (auto &c : str)
c = toupper(c);
cout << str;
return 0;
}
这段C++代码无法编译。
错误消息:
main.cpp:21: error: a function-definition is not allowed here before ':' token
问题:
C++中是否有foreach循环(范围for循环)?上述foreach循环有什么问题?
先行致谢。