语言:使用C++语言
问题:本身有个.txt档, 需判断九九乘法表哪行出错,
并在萤幕上印出 "第XX行出错字样"
(.txt档 内容如下)
4x2=8
4x3=12
1667475582
4x5=20
4x6=24
4x7=28
4x8=32
4x9=36
这是我的程式码:
include <iostream>
#include <string>
#include <fstream>
#include <cctype>
using namespace std;
int main()
{
ifstream fip("data2.txt");
if(!fip){
cout << "输入档案[data2.txt]无法开启" << '\n';
return -1;
}
int time = 0;
string str;
while(getline(fip, str)){
time++;
if(str.isdigit())
cout << "第" << time << "行错误!\n"
<< str[0] << "X" << time << " = " << time*str[0];
else
{}
}
fip.close();
return 0;
}
想要判断整行字串是否皆为数字, 若是输出"第XX行错误"
程式编译不过, 是不是isdigital用错了!
该如何改善, 谢谢!