#include <iostream>
#include <fstream>
#include <string>
#include <cctype> // isdigit();
using namespace std;
int main()
{
ifstream fin;
fin.open("Sayı.txt");
while (!fin.eof()){
string word;
int n;
fin >> word; //First i read it as a string.
if (isdigit(word[0])){ //checks whether is it an int or not
fin.unget(); //
fin >> n; // if its a int read it as an int
cout << n << endl;
}
}
}
假设文本文件是这样的:
100200300 Glass
Oven 400500601
我的目标只是从该文本文件中读取整数并在控制台中显示它们。所以输出应该像
100200300
400500601
您可以在上面看到我的尝试。作为输出,我只得到整数的最后一位。这是一个示例输出:
0
1