[问题] 字串判断是否为乱数

楼主: plowsavior (咕噜咕咕)   2015-07-30 11:43:38
语言:使用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用错了!
该如何改善, 谢谢!
作者: Feis (永远睡不着 @@)   2015-07-30 12:53:00
是这题目应该不需要用到 isdigital要用的话你就 google 一下 isdigit 的用法. 跟你想的差很多
作者: Killercat (杀人猫™)   2015-07-30 16:04:00
这个其实该用regex, 你可以参考一下一些std::regex*
作者: EdisonX (卡卡兽)   2015-07-30 17:47:00
擅用sscanf或fscanf传回值。
楼主: plowsavior (咕噜咕咕)   2015-07-30 20:47:00
好的,感谢!^^
作者: stupid0319 (征女友)   2015-07-30 23:17:00
这个用char*来做应该满快的吧?

Links booklink

Contact Us: admin [ a t ] ucptt.com