我正在通过本书(第5版)学习C++,今天我在做练习12.6时遇到了一个问题。
代码如下所示,错误是this declaration has no storage class or type specifier
。但是程序可以正常运行。错误位于“}”的最后一行。
#include<iostream>
#include<vector>
#include<new>
using namespace std;
vector<int>* func(){
return new vector<int>();
}
void read_vec(istream &in, vector<int>* vp){
int i;
while(in>>i)
vp->push_back(i);
}
void print_vec(vector<int>* vp){
for(int i:*vp)
cout<<i<<" ";
cout<<endl;
}
int main(){
auto vec = func();
cout<<"Enter a sequence of integers"<<endl;
read_vec(cin,vec);
print_vec(vec);
delete vec;
vec = nullptr;
system("pause");
}
我已经搜索了消息,但仍然无法找出我的代码错误的地方。
我将不胜感激所有提示。
最佳答案
你需要标准库头<cstdlib>
使用 system
.
添加
#include <cstdlib>
在文件的顶部。然后,使用 std::system
而不仅仅是 system
.
std::system("pause");
关于c++ - C++ 中的 "declaration has no storage class or type specifier",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56334621/