从输入文件读取内容到vector c ++

时间:2016-04-18 22:30:41

标签: c++ vector

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;

int getInputFileName(); //function to get and store content in file to vector
int getOutputFileName();

int main()
{
getInputFileName();
getOutputFileName();
}

int getInputFileName()
{
vector<Student> s;
ifstream input;
string inputFileName;

cout << "What is the name of the input file you are going to use: " << endl;
cin >> inputFileName;

input.open(inputFileName);

while (input.fail()) // check to see if inputFileName opened
{
    cout << "Error! Incorrect file name." << endl;
    cout << "Enter the correct name of the input file you want to use: " << endl;
    cin >> inputFileName;
}

有人可以帮我解决这个问题吗?我需要将文件的内容读入向量s。我对矢量有点困惑,因为我教授过去的那天我不在。我不知道如何将文件读入矢量。请帮忙,不要对我太粗暴,谢谢你提前!!

for(i = 0; i > )
}

int getOutputFileName()
{

ofstream output;
string outputFileName;

cout << "What is the name of the output file you are going to use: " << endl;
cin >> outputFileName;

output.open(outputFileName);

while (output.fail())  // check to see if inputFileName opened
{
    cout << "Error! Incorrect file name." << endl;
    cout << "Enter the correct name of the output file you want to use: " << endl;
}
}

0 个答案:

没有答案