[問題] 字串判斷是否為亂數
語言:使用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用錯了!
該如何改善, 謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.112.32
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1438227825.A.983.html
→
07/30 12:53, , 1F
07/30 12:53, 1F
→
07/30 12:54, , 2F
07/30 12:54, 2F
→
07/30 12:55, , 3F
07/30 12:55, 3F
推
07/30 16:04, , 4F
07/30 16:04, 4F
推
07/30 17:47, , 5F
07/30 17:47, 5F
→
07/30 20:47, , 6F
07/30 20:47, 6F
推
07/30 23:17, , 7F
07/30 23:17, 7F