(C++) Reading digits from text file

后端 未结 2 458
囚心锁ツ
囚心锁ツ 2021-01-07 09:57

I have a text file which looks like this:

73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 85

2条回答
  •  春和景丽
    2021-01-07 10:35

    char digit;
    std::ifstream file("digits.txt");
    std::vector digits;
    // if you want the ASCII value of the digit.
    1- while(file >> digit) digits.push_back(digit);
    // if you want the numeric value of the digit.
    2- while(file >> digit) digits.push_back(digit - '0'); 
    

提交回复
热议问题