【发布时间】:2015-11-01 01:00:09
【问题描述】:
我创建了一个名为 program.txt 的数据文件。我需要创建代码,从该 program.txt
中打印出行数和整数值
这是我写的文字
1
35
45
87
9
100
program.text 中有这些值
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string calc;
int test;
int cool;
int book;
ifstream myfile;
ifstream outof;
myfile.open ("program.txt");
outof.open("program.txt");
if (myfile.fail())
{
cerr<<"Error Opening file"<<endl;
}
if(outof.fail ())
{
cerr<<"Error Opening file"<<endl;
}
while (!myfile.eof ())
{
getline(myfile,calc);
++book;
}
cout <<book<<endl;
while (!outof.eof ())
{
outof<<test;//
cool++;
}
cout<<cool<<endl;
myfile.close();
outof.close();
}
在 cerr 之后,我尝试了退出 (1),它说退出未定义。 我是新手,任何帮助将不胜感激。谢谢 这是 C++ 顺便说一句。
【问题讨论】: