473,804 Members | 4,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String to int/double conversion and parsing

Hi all,

Given the following data format: { "(1,2), "(2.5, 3.5)", .... }

I would like to define a vector<string> to stored this data:

v[0] = "(1,2)", v[1] = "(2.5, 3.5"), ....

and would like to extract the integer/double string value to real
int/double and use it in computation. What is the best way to do it?
Currently, I am using C routine atoi() and wrote a litter paring
function to extract the int/double value. I would like to know if
there is a better way to do in using STL and maybe its algorithm?

THanks,
Kaede
Jul 22 '05 #1
1 2249
"kaede" <ka************ @hotmail.com> wrote in message
news:60******** *************** ***@posting.goo gle.com...
Hi all,

Given the following data format: { "(1,2), "(2.5, 3.5)", .... }

I would like to define a vector<string> to stored this data:

v[0] = "(1,2)", v[1] = "(2.5, 3.5"), ....

and would like to extract the integer/double string value to real
int/double and use it in computation. What is the best way to do it?
Currently, I am using C routine atoi() and wrote a litter paring
function to extract the int/double value. I would like to know if
there is a better way to do in using STL and maybe its algorithm?


Ditch atoi() and use something that has more reasonable behavior when passed
invalid input, like a stringstream. Other than that, the best solution
would probably involve iterating over the std::vector and parsing each
element (e.g. std::pair<doubl e,double> parseDoubles(co nst std::string& s)).
You might be able to come up with something that uses <algorithm>, like
std::transform, but the code would probably look unnatural.

--
David Hilsee
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1945
by: Dan Perl | last post by:
Is there a way to convert a regular string to a raw string so that one could get from '\bblah' to r'\bblah' other than parsing the string and modifying the escapes? I am interested in this for the use of regular expressions. I would like to be able to accept re patterns as inputs either from a file or from a GUI tool and I would like to allow those inputs as regular strings and not force users to write patterns with double escapes. I...
12
2218
by: ABeck | last post by:
Hello List, I have ar more or less academical question. Can there arise runtime errors in a program, if the include of <string.h> has been forgotten? If all the arguments to the functions of <string.h> are correct, is it possible that an error occurs, and what an error might this be? Regards
8
3275
by: Oenone | last post by:
Is it possible to create an object which can have methods and properties, but which can also be treated as a string? I'm trying to create a wrapper around the IIS Request.Form object which behaves the same as the classic ASP object behaved. This will allow me to quickly get a large amount of code up and running (I can then tweak it to not require this wrapper at a more leisurely pace). When queried directly, this object returns a...
16
5889
by: Charles Law | last post by:
I have a string similar to the following: " MyString 40 "Hello world" all " It contains white space that may be spaces or tabs, or a combination, and I want to produce an array with the following elements arr(0) = "MyString" arr(1) = 40 arr(2) = "Hello world"
6
7616
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards, Karthi
14
2938
by: nishit.gupta | last post by:
Is their any single fuction available in C++ that can determine that a string contains a numeric value. The value cabn be in hex, int, float. i.e. "1256" , "123.566" , "0xffff" , It can also contain zero
2
2119
by: Nicolai.Schoenberg | last post by:
When i try it like you say, he ignores the dot. For example s = "12.45"; d = double.Parse(s); d will be 1245.0 :( pls help
14
2172
by: Aman JIANG | last post by:
hi i need a fast way to do lots of conversion that between string and numerical value(integer, float, double...), and boost::lexical_cast is useless, because it runs for a long time, (about 60 times slower than corresponding C functions) it's too expensive for my program. is there any way( library?) to do this fast and safely, please ?
6
4738
by: (2b|!2b)==? | last post by:
I am expecting a string of this format: "id1:param1,param2;id2:param1,param2,param3;id" The tokens are seperated by semicolon ";" However each token is really a struct of the following format: struct mst_ {
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10076
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4297
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3816
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.