gpt4 book ai didi

C++:如何编写程序从文件中读取整数?

转载 作者:太空宇宙 更新时间:2023-11-04 15:10:15 25 4
gpt4 key购买 nike

当我使用书中推荐的代码时,出现错误。我正在使用适用于 Mac 的 NetBeans 6.8。

代码如下:

#include <iostream>
#include <fstream>
using namespace std;

int main()
{

ifstream inputFile;

int number;

inputFile.open("MacintoshHD/Users/moshekwiat/Desktop/random.txt");

inFile >> number;

cout<<endl <<number<<endl;

inputFile.close();

return (0);
}

这里是错误:

main.cpp:20: error: 'inFile' was not declared in this scope

需要做什么??谢谢你

最佳答案

将 inFile 替换为 inputFile。

关于C++:如何编写程序从文件中读取整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3158833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com