我这些天自己学习C++并且我有一些问题需要理解为什么这段代码不能编译使用#g++ -std=c++11 source.cpp
.实际上我使用哪个特定标准并不重要,它只是不编译.
#include <iostream>
#include <string>
using namespace std;
int print_a(char array[])
{
for(char c : array)
cout << c;
cout << endl;
return 0;
}
int main(void)
{
char hello[] {"Hello!"};
print_a(hello);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
错误消息:
debian@debian:~/Documents$ g++ -std=c++11 source.cpp
source.cpp: In function ‘int print_a(char*)’:
source.cpp:6:15: error: ‘begin’ was not declared in this scope
for(char c : array)
^
source.cpp:6:15: note: suggested alternatives:
In file included from /usr/include/c++/4.9/bits/basic_string.h:42:0,
from /usr/include/c++/4.9/string:52,
from /usr/include/c++/4.9/bits/locale_classes.h:40,
from /usr/include/c++/4.9/bits/ios_base.h:41,
from /usr/include/c++/4.9/ios:42, …
Run Code Online (Sandbox Code Playgroud)