O
O
olkhovich2019-11-19 22:55:48
C++ / C#
olkhovich, 2019-11-19 22:55:48

How to find all the numbers in a string and form a new one from them?

Task: A
character string is entered from the keyboard. You need to find all the numbers and form a new string from them.
I understand how this can be done through a char array. But is it possible to somehow implement it through string? If so, how?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2019-11-19
@olkhovich

Need a sort function

No.
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
  string src;
  getline(cin, src);

  string dst;
  copy_if(src.begin(), src.end(), back_inserter(dst), ::isdigit);

  cout << dst;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question