Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将多个.txt文件读入向量<;双倍>;_C++ - Fatal编程技术网

C++ 将多个.txt文件读入向量<;双倍>;

C++ 将多个.txt文件读入向量<;双倍>;,c++,C++,你好 我编写了以下函数,它是某些计算的一部分: vector<double> read(){ cout << "Add file to calculate, example: name.txt" << endl; char file; double numz; vector<double> myvector; char str[256]; ifstream fin; cin.get (str,

你好

我编写了以下函数,它是某些计算的一部分:

vector<double> read(){
    cout << "Add file to calculate, example: name.txt" << endl;
    char file;
    double numz;
    vector<double> myvector;
    char str[256];
    ifstream fin;
    cin.get (str,256);
    fin.open (str);
    while(fin.good()){

            fin>>numz;
            myvector.push_back(numz);

    }
    return myvector;


}  

我一整天都在寻找解决办法,但似乎什么都不管用。提前感谢您提供有关如何解决此功能的提示和建议。

您可以从输入行创建一个
istringstream
,并使用它提取文件名:

//...
cin.get(str, 256);
string str2(str);
istringstream input(str2);
string filename;
while (input >> filename) {
  istream fin(filename.c_str());
  //... process as before
}

我认为问题出在退货部分。如果是这样,你可以考虑指针指向向量的返回。
vector<vector<double>*> read()
向量读取()
对于旧版本的C++,使用<代码> ISTIGISSWILE输入(STR2.CyScript())< /C>。
vector<vector<double>*> read()