0

Пример кода:

#inclde<fstream>

using namespace std;

ifstream in("input.txt");

int main()
{
    int templateINT;
    char templateCHAR;
    in >> something from this;
    return 0;
}
4
  • Поясните понятнее, что вам нужно...
    – Harry
    4 мая 2018 в 17:20
  • Что делает этот пример кода? 4 мая 2018 в 17:20
  • Хочет считывать из input.txt [adsfddggd 75] только цифры 4 мая 2018 в 17:21
  • Пример входных данных: 19:20 4 мая 2018 в 17:31

2 ответа 2

0
int k = 0;
while(true) {
if (!isdigit(char (in.peek())))
        in.ignore();
    else  {
        in >> k;
        cout << k << ' ';
    }
}

Можете не выводить, а хранить цифры в контейнере

0
void process(const std::string& str, std::vector<int>& numbers) {
    for (std::string::size_type i = 0; i < str.size(); ++i)
        if (isdigit(str[i])) numbers.push_back(int(str[i]) - 48);
}

string line;
std::vector<int> numbers;
ifstream f ("file");
if (!f.is_open()) {
    perror("error while opening file");
    return -1;
}
while(getline(f, line))
    process(&line, numbers);

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.