473,326 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

string differences; max irritation

Please what is the functional C++ difference between a string of characters
typed manually and included inside the main() function of a program...

vis:
string str = "123,4.56,7.8"; ,

....and _exactly the same string_, read into a string variable from a file
via getline()
vis:
getline(fileobject, str, ','); ?
(I'm parsing this line with three getline()s; output via cout is "123" then
"4.56" then "7.8")

I can't get getline()'s string to work with strtod() in the same program,
but the manually typed string works perfectly with strtod() in a program all
by itself, and the getline()-read-and-parse works perfectly in a program all
by itself.
This is making no sense to me.

The file contains double-precision numbers (as characters), the three you
see above (they vary, file to file), and many other lines (\n=terminated) of
three doubles each.
The manually typed and-inside-the-main() string is also numbers (as
characters).

So: _what's different_ ??
I'd think a string of characters is a string of characters, regardless of
where it comes from, the only difference I've been able to find being that
between C++ strings (which these have to be), and C strings (which have a \0
null character at the end).
No null characters.
WHY can't I read these characters in from the file, then get my decimal
floats back with strtod() ? I can do either _independently_, just not
together.

I'm stumped, and I _have_ done my 'homework' --days of it--
searching/reading on the web, trying various code snippets found (which is
why strtod() works with the manually written numbers), asking e-friends,
etc.
This is nuts.
It should be _easy_ and simple, to get a number from a file and have it BE a
number when I need it in the program. (It was easy in Python; I did all
this before. It's crazy in C++.)

Thanks
(*whimper*)
--
Peace
JB
jb@tetrahedraverse.com
Web: http://tetrahedraverse.com


Jan 24 '08 #1
2 1391
To Alf:
My apologies.
I read the FAQ B4 the post.
I'm trying to comply, by doing as much as I can externally, and by asking
for hints, leads, pointings-in-the-right-direction B4 posting loads of
working / nonworking code.

To Kasthurirangan Balaji:
Your example code is alien to me (newbie; Python handyman/toolbox graduate),
but I will try to grasp it and study it and use it to try to figure out why
mine isn't working.
And, _thank_you_!

If this doesn't help, I'll try again, this time with the runnable (and non-)
code inline.
--
Peace
JB
jb@tetrahedraverse.com
Web: http://tetrahedraverse.com

Jan 24 '08 #2
Update (minutes later):
To Balaji:
THANK YOU.
It compiles, runs, and I understand it now.
Your grasp of my problem was perfect.
Your code was perfect: clean, brief, functional, elegant, _exactly_ what I
needed to see.
I am in your debt.

(My first post may have been improper in some way (maybe this one is also),
but Balaji, you got the essence of the problem from it.
Sorry, Alf.)

--
Peace
JB
jb@tetrahedraverse.com
Web: http://tetrahedraverse.com

Jan 24 '08 #3

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

Similar topics

37
by: Kevin C | last post by:
Quick Question: StringBuilder is obviously more efficient dealing with string concatenations than the old '+=' method... however, in dealing with relatively large string concatenations (ie,...
35
by: michael.casey | last post by:
The purpose of this post is to obtain the communities opinion of the usefulness, efficiency, and most importantly the correctness of this small piece of code. I thank everyone in advance for your...
0
by: foldface | last post by:
Hi As the subject says. If you run VS with an asp.net solution then your program just runs. If you do a ctrl-f5 to restart the solution then it first breaks in the javascript before continuing....
10
by: Tom Dacon | last post by:
One thing that drives me nuts about coding in VB.Net is the behavior of the IDE when you split the code window in two by dragging down the separator at the top of the vertical scroll bar. If you...
18
by: Kyro | last post by:
New to C# (migrating from Delphi) and I'm not sure how to get a delimited string into an array of string. input: string looks like - 01-85-78-15-Q11 output: an array with elements - ...
2
by: Jeroen | last post by:
We have update operations on strings, where we know the "New" and "Old" version of the string. A html report will be generated about many of these changes. I would like to mark these changes with...
41
by: Dead Loop | last post by:
Hi all, I'm a beginner and my question is: Are there any differences between char *p = "Hello, world!"; and const char *p = "Hello, world!"; ?
92
by: =?Utf-8?B?bW9iaWxlbW9iaWxl?= | last post by:
I'm trying to load this structure for a call to DeviceIoControl: typedef struct _NDISUIO_QUERY_OID { NDIS_OID Oid; PTCHAR ptcDeviceName; UCHAR Data; } NDISUIO_QUERY_OID, *PNDISUIO_QUERY_OID; ...
13
by: Jen | last post by:
One user of my application is experiencing an exception "input string not in correct format". But it makes no sense where it is occurring. It is occurring when a string from a textbox ("172") is...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.