getting numbers from string

T

Tan Thuan Seah

Hi all,

I have a string with several numbers in it. The numbers each can be up to
14 characters.(i.e ---------12345---------1234, where - represents spaces).
Is there any way to retrieve the number apart from using sscanf?

Thuan Seah



------------ And now a word from our sponsor ------------------
For a quality usenet news server, try DNEWS, easy to install,
fast, efficient and reliable. For home servers or carrier class
installations with millions of users it will allow you to grow!
---- See http://netwinsite.com/sponsor/sponsor_dnews.htm ----
 
M

Mike Wahler

Tan Thuan Seah said:
Hi all,

I have a string with several numbers in it. The numbers each can be up to
14 characters.(i.e ---------12345---------1234, where - represents spaces).
Is there any way to retrieve the number apart from using sscanf?

#include <iostream>
#include <sstream>
#include <string>

int main()
{
std::string s(" 12345 1234");
std::istringstream iss(s);
unsigned long number(0);

while(iss >> number)
std::cout << number '\n';

return 0;
}

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top