【发布时间】:2021-07-18 06:27:27
【问题描述】:
尝试调用函数时,我的代码中出现错误。我已经尝试了几种不同的方法,但我就是无法让它发挥作用,我知道这一定很愚蠢。
#include <iostream>
#include <fstream>
using namespace std;
void openFile(string input);
int main()
{
string input;
cout << "Please enter a file to open: " << endl;
cin >> input;
void openFile(input); //error is right here!!!!!!!!!
return 0;
}
void openFile(string input) {
ifstream in_file;
in_file.open(input);
if (in_file.fail())
cout << "Something went wrong, file did not open!!!" << endl;
else {
cout << "File opened successfully!!!" << endl;
cout << in_file.rdbuf() << endl;
}
in_file.close();
}
【问题讨论】:
-
在给出路径时是否给出了双反斜杠,而不是单反斜杠?
-
投票关闭为错字:这不是你调用函数的方式。
-
哎呀,我没注意,是的,他的语法不正确
-
@Jeremy Mahan 你不应该写一个 void 来调用一个函数。
标签: c++ incomplete-type