如何声明结构类型的向量?

1 c++ structure vector

我的代码有问题.在这里,我想编写一个程序,它将从文件中获取输入并将其存储在结构向量中,但是当我声明结构类型向量时,它显示错误.

#include<iostream>
#include<fstream>
#include<vector>

using namespace std;

struct input
{
    char process[10];
    int burst_time;
    int arrival_time;
}input;

int main()
{
    ifstream myfile;
    vector<input> store;// problem with initializing vector

    myfile.open("input.txt",ios::in);

    if(myfile.is_open())
    {
        while(!myfile.eof())
        {
            myfile>>input.process;
            myfile>>input.burst_time;
            myfile>>input.arrival_time;

            store.push_back(input);//showing problem in this line also
        }
    }

    myfile.close();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

jua*_*nza 7

您已将该名称隐藏input为其实例struct input.取消隐藏它:

struct intput
{
 // as before
};
Run Code Online (Sandbox Code Playgroud)