[英]“declaration has no storage class or type specifier” in C++
I'm learning C++ through the book (5th Edition),today I encounter a problem when doing the exercise 12.6. 我正在通过本书(第5版)学习C ++,今天在练习12.6时遇到问题。
The code is shown below, the error is this declaration has no storage class or type specifier
. 代码如下所示,错误是this declaration has no storage class or type specifier
。 But the program can run normally. 但是程序可以正常运行。 The error locates at the last line on '}'. 错误位于“}”的最后一行。
#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");
}
I have searched the message, but still cannot figure out where my code is wrong. 我已经搜索了该消息,但是仍然无法找出我的代码在哪里。
I would be appreciative for all hints. 对于所有提示,我将不胜感激。
You need the standard library header <cstdlib>
to use system
. 您需要标准库头文件<cstdlib>
才能使用system
。
Add 加
#include <cstdlib>
at the top of the file. 在文件的顶部。 Then, use std::system
instead of just system
. 然后,使用std::system
而不是system
。
std::system("pause");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.