Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.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++ 如何将变量放入file.open()中_C++_Arrays_String_Variables_Loops - Fatal编程技术网

C++ 如何将变量放入file.open()中

C++ 如何将变量放入file.open()中,c++,arrays,string,variables,loops,C++,Arrays,String,Variables,Loops,我试图在file.open()函数中放入变量文件名,但始终出现以下错误: [错误]调用'std::basic_of stream::open(std::string&')时没有匹配的函数。 守则: for (int x=1; x<=num_pages; x++){ file= page_name[x]; cout << file; ofstream file; file.open ("file"); ... file.close(); } for(int x=

我试图在file.open()函数中放入变量文件名,但始终出现以下错误:

[错误]调用
'std::basic_of stream::open(std::string&')时没有匹配的函数。

守则:

for (int x=1; x<=num_pages; x++){
    file= page_name[x];
    cout << file;
ofstream file;
file.open ("file");
...
file.close();
}

for(int x=1;x您不能有两个同名变量。您似乎正在尝试命名字符串
文件
以及流的
。请尝试将第一个变量(字符串)重命名为
文件名
。然后您可以执行以下操作:

file.open(filename);

当你说“出错”时,你还必须告诉我们错误是什么,这样我们就不必猜测了。你面前就有这些信息(如果你没有,你就不会知道你出错了),所以你应该把它包括在你的问题中。我们坐在那里看不到你的屏幕。:-@KenWhite[错误]调用“std::basic_of stream::open(std::string&)”时没有匹配的函数,请将您的问题包含在那里,以便阅读它的人可以看到它。你不应该把重要的信息放在评论里。@KenWhite我会贴出来你知道哪里错了吗