"declaration has no storage class or type specifier" C++

"declaration has no storage class or type specifier" in C++

本文关键字:type specifier C++ or storage declaration has no class      更新时间:2023-10-16

我正在通过书(第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");
相关文章: