473,881 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

strtod(*iter) + double

Hi

I have a
vector<stringwh ich holds numbers, I need to loop and printout those
numbers + a value as doubles .

typedef vector<string>: :const_iterator vs_itr;
for(vs_itr i=vect.begin(); i!=vect.end(); ++i){
cout << *i << '\t' << strtod(*i)+val << '\n';

isn't de-referencing the iterator puts out its string value?

I am getting

gen_data.cpp:62 : error: cannot convert 'const std::basic_stri ng<char,
std::char_trait s<char>, std::allocator< char' to 'const char*' for
argument '1' to 'double strtod(const char*, char**)'

thanks
Aug 7 '06 #1
4 2470
Gary Wessle wrote:
Hi

I have a
vector<stringwh ich holds numbers, I need to loop and printout those
numbers + a value as doubles .

typedef vector<string>: :const_iterator vs_itr;
for(vs_itr i=vect.begin(); i!=vect.end(); ++i){
cout << *i << '\t' << strtod(*i)+val << '\n';

isn't de-referencing the iterator puts out its string value?

I am getting

gen_data.cpp:62 : error: cannot convert 'const std::basic_stri ng<char,
std::char_trait s<char>, std::allocator< char' to 'const char*' for
argument '1' to 'double strtod(const char*, char**)'
The error is telling exactly what's wrong, strtod takes a const char*,
not a std::string. Look up string.c_str()

--
Ian Collins.
Aug 7 '06 #2
Ian Collins <ia******@hotma il.comwrites:
Gary Wessle wrote:
>Hi

I have a
vector<stringw hich holds numbers, I need to loop and printout those
numbers + a value as doubles .

typedef vector<string>: :const_iterator vs_itr;
for(vs_itr i=vect.begin(); i!=vect.end(); ++i){
cout << *i << '\t' << strtod(*i)+val << '\n';

isn't de-referencing the iterator puts out its string value?

I am getting

gen_data.cpp:6 2: error: cannot convert 'const std::basic_stri ng<char,
std::char_trai ts<char>, std::allocator< char' to 'const char*' for
argument '1' to 'double strtod(const char*, char**)'
The error is telling exactly what's wrong, strtod takes a const char*,
not a std::string. Look up string.c_str()

--
Ian Collins.
I actually was trying to fix it using

out<< setw(10) << *i << strtod(*i.c_str (),0)+val << '\n';
for no avail, here the *i puts out a string, c_str() converts it to a
char*, why is it complaining still?
saying vs_itr' has no member named 'c_str', then what am going to
apply c_str() upon? should I cast *i into a string?
Aug 7 '06 #3
Gary Wessle schrieb:
out<< setw(10) << *i << strtod(*i.c_str (),0)+val << '\n';
for no avail, here the *i puts out a string, c_str() converts it to a
char*, why is it complaining still?
saying vs_itr' has no member named 'c_str', then what am going to
apply c_str() upon? should I cast *i into a string?
Look up the operator precedence table:

"." has higher precedence than prefix-*, so *i.c_str() is parsed as
*(i.c_str()), but you want (*i).c_str() or simply i->c_str()

Instead of strtod, you could use the method that is in the FAQ:
http://www.parashift.com/c++-faq-lit....html#faq-39.2

--
Thomas
Aug 7 '06 #4
Gary Wessle wrote:
Ian Collins <ia******@hotma il.comwrites:
>Gary Wessle wrote:
>>Hi

I have a
vector<string which holds numbers, I need to loop and printout those
numbers + a value as doubles .

typedef vector<string>: :const_iterator vs_itr;
for(vs_itr i=vect.begin(); i!=vect.end(); ++i){
cout << *i << '\t' << strtod(*i)+val << '\n';

isn't de-referencing the iterator puts out its string value?

I am getting

gen_data.cpp: 62: error: cannot convert 'const std::basic_stri ng<char,
std::char_tra its<char>, std::allocator< char' to 'const char*' for
argument '1' to 'double strtod(const char*, char**)'
The error is telling exactly what's wrong, strtod takes a const char*,
not a std::string. Look up string.c_str()

--
Ian Collins.

I actually was trying to fix it using

out<< setw(10) << *i << strtod(*i.c_str (),0)+val << '\n';
for no avail, here the *i puts out a string, c_str() converts it to a
char*, why is it complaining still?
saying vs_itr' has no member named 'c_str', then what am going to
apply c_str() upon? should I cast *i into a string?
Try strtod( (*i).c_str(), 0).

the . operator binds tighter that '*', so you had the equivalent of
*(i.c_str()), which won't work.

Aug 7 '06 #5

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

Similar topics

3
5466
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hi, I want to replace: char *text; double val = strtod(text,NULL); by an equivalent using std::string in the place of char *.
1
3030
by: Mathieu Malaterre | last post by:
Hello, I would like to have some advices on this problem I am having. In my code I have hardcoded a string like: const char foo = "11 0.438482 "; I was then calling strtod to transform it back to double. Unfortunately depending on the LOCALE settings, the strtod could fail.
21
2295
by: Marky C | last post by:
atof is not working. double a = atof("12.345"); a gets set to 12.000 I am working on a toshiba micro. The data map has no space allocated to it for dynamic memory. Does anyone have an idea? Could it be due to the lack of dynamic
7
10043
by: Dawn Minnis | last post by:
hey guys i have char *argv to receive command line arguements. I can get characters out no problem I can get integers parsed out no problem But how do I get double values. eg if my program is called test and I run it as test n t 3 4 2.4 3.55
9
1979
by: Adam Warner | last post by:
Hi all, Message ID <c1qo3f0tro@enews2.newsguy.com> is one of many informative articles by Chris Torek about C. The particular message discusses aliasing and concludes with this paragraph: Under these strict type-aliasing rules, casting from (e.g.) "int *" to "short *" is not only quite suspicious, it is also likely to cause puzzling behavior, at least if you expect your "short *" to access or modify your "int". Even the time-honored,...
18
2462
by: coder | last post by:
Hi experts, Is the following usage of strtod okay (p is a char pointer): value = strtod(p, &p); Is it possible that this would evoke undefined behaviour? Or should I use a temporary pointer and then assign its value to p? Thanks
8
3493
by: Bill Cunningham | last post by:
Since I've been told that char *argv or char **argv must be the second parameter to main's command line structure I have turned to strtod( ) but can't get it to work so far. This function is probably used alot but I obviously am not using it right. #include <stdio.h> int main(int argc, char **argv) { if (argc != 3) {
4
1633
by: Bob Nelson | last post by:
Fellow C pushers: Deliberately avoiding a look at Jack Klein's bulletproof code for a robust use of strtol(), I respectfully submit the following for review and vigorous critique, desiring unapologetic pedantry (in the *very* best sense of that word). In the way of background, I may as well be a C newbie since the nature of my job has not involved day to day use of the language for maybe a decade. Although I am entering my ``golden...
22
2789
by: Bill Reid | last post by:
I just noticed that my "improved" version of sscanf() doesn't assign floating point numbers properly if the variable assigned to is declared as a "float" rather than a "double". (This never cropped up before, since I rarely use "float"s for anything, and hardly ever use the function for floating-point numbers in the first place; I just was messing around testing it for all cases and noticed a problem.) Anyway, it is declared and I...
0
9926
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
10716
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10812
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
9552
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7952
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7108
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4597
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
4194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3223
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.