J
John Brawley
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*)
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*)