Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.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++中编码时不能在VS代码中使用AutoType关键字 我使用VS代码来对C++进行编码。它的性能非常好。但每当我在代码中使用auto关键字时,程序就无法编译_C++_C++11_Visual Studio Code_C++14 - Fatal编程技术网

在C++中编码时不能在VS代码中使用AutoType关键字 我使用VS代码来对C++进行编码。它的性能非常好。但每当我在代码中使用auto关键字时,程序就无法编译

在C++中编码时不能在VS代码中使用AutoType关键字 我使用VS代码来对C++进行编码。它的性能非常好。但每当我在代码中使用auto关键字时,程序就无法编译,c++,c++11,visual-studio-code,c++14,C++,C++11,Visual Studio Code,C++14,例如,在不使用auto关键字的情况下迭代字符串,代码如下所示 #include <iostream> #include <string> using namespace std; int main() { string s("Hello"); for(int i=0;i<s.length();i++) { cout<<s.at(i)<<' '; } cin.get()

例如,在不使用auto关键字的情况下迭代字符串,代码如下所示

#include <iostream>
#include <string>
using namespace std;
int main()
{
    string s("Hello");
    for(int i=0;i<s.length();i++)
    {
        cout<<s.at(i)<<' ';
    }
    cin.get();
}
请帮帮我。

这是线索:

正在执行的任务:g++-g-o helloworld helloworld.cpp

我怀疑您需要使用-std=c++11或更高版本进行编译

在导入自动关键字之前,GCG/G+的旧版本将默认为C++ 98标准。可能还有其他默认配置。解决方法很简单

配置生成,使编译的任务如下:

g++ -std=c++11 -g -o helloworld helloworld.cpp 

如果使用GCC版本低于6,则它也可以使用-STD= C++ 14或-STD= C++ 17。如果使用GCC版本不低于新的C++标准版本,则需要明确地告诉编译器,它应该使用已经提到的-STD+C++ 11选项来启用这些特性。

Executing task: g++ -g -o helloworld helloworld.cpp 

helloworld.cpp: In function 'int main()':
helloworld.cpp:7:14: error: 'c' does not name a type
     for(auto c:s)
              ^
helloworld.cpp:11:5: error: expected ';' before 'cin'
     cin.get();
     ^
helloworld.cpp:12:1: error: expected primary-expression before '}' token
 }
 ^
helloworld.cpp:12:1: error: expected ')' before '}' token
helloworld.cpp:12:1: error: expected primary-expression before '}' token
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it. 
g++ -std=c++11 -g -o helloworld helloworld.cpp