C++编译错误
C++ compile error
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream inputFile;
string example;
int numbers,
totalNumbers = 0;
// Prompt user to input name of the file to open
cout << "Please enter the name of the program" << endl;
cin >> example;
// Open the input file that is assigned to the variable 'example'
inputFile.open(example.c_str());
// If the file successfully opened, process it
if(inputFile)
{
// Loop until the EOF is reached
while(inputFile >> numbers) // If a value was read
{
totalNumbers += numbers;
}
// Close the file
inputFile.close(example.c_str());
cout << totalNumbers;
}
else
{
// Display an error message
cout << "could not access file";
}
return 0;
}
错误如下:
fileAdder.cpp: 在函数 'int main((' 中:fileAdder.cpp:36:40:错误:调用"std::basic_ifstream::关闭(const char*("没有匹配函数 inputFile.close(example.c_str(((; ^文件添加.cpp:36:40:注意:候选人是:在 fileAdder.cpp:8:0 中包含的文件中:/usr/include/c++/4.8.2/fstream:576:7: 注意: void std::basic_ifstream<_CharT, _Traits>::close(( [_CharT = char; _Traits = std::char_traits] 关闭(( ^/usr/include/c++/4.8.2/fstream:576:7:注意:候选人需要 0 个参数,提供 1
>ifstream::close
不接受任何参数。
将第 36 行更改为inputFile.close();
删除 example.c.str((
正确的陈述是:
inputFile.close();
我们不需要传递参数
相关文章:
- 用MacOS Mojave编译C++:致命错误:mpi.h:没有这样的文件或目录
- std::is_base_of表示ctor编译错误
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- Qt5:使用QCommandLineParser类时出现奇怪的编译错误
- Qt Cmake 错误编译"GuiSupportQt not found"
- Opengl 精度转换错误编译错误 E0415
- 库将ARM架构错误编译为架构X64
- RT 音频 Mac 错误 g++ 编译错误
- 错误编译Boost.log
- 错误编译QT创建者 / QT窗口小部件示例
- 错误编译MIPS32
- Visual Studio 2013 中的错误(编译和运行代码)
- 链接错误编译qt项目在visual 2010
- 无法用模板错误编译nsgmls
- 奇怪的错误.编译失败
- 如果有人调用c++中的方法,则强制错误(编译时)
- 来自autoconf测试的错误编译命令
- 时间限制超出错误C++编译
- SFML 2.3 和 CodeBlocks 错误编译