LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-14-2003, 02:30 AM   #1
danxl
LQ Newbie
 
Registered: Jul 2003
Posts: 11

Rep: Reputation: 0
istringstream???


This don't compile, why?

#include <iostream>
#include <string>
int main()

{
std::string stringvalues;
stringvalues = "31.5";

// error message with this line, say: varialbe 'std::istringstream iss' has but incomplete type
std::istringstream iss(stringvalues);
double f;
iss>>f;
std::cout <<"Value is:"<< f <<std::endl;
return (0);
}

g++ verison is 3.3.2
 
Old 10-14-2003, 02:47 AM   #2
danxl
LQ Newbie
 
Registered: Jul 2003
Posts: 11

Original Poster
Rep: Reputation: 0
Add a line like this, now it is OK.

#include <sstream>
 
Old 10-16-2003, 06:08 AM   #3
UltimaGuy
Member
 
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 32
And I don't think that you should use istringstreams, as it is better to stick with strings or c style character arrays. This is because the implementation of istringstreams are vendor dependent, and your resultant program may not be portable if you use them.
 
Old 10-16-2003, 06:47 AM   #4
dakensta
Member
 
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194

Rep: Reputation: 35
Quote:
This is because the implementation of istringstreams are vendor dependent, and your resultant program may not be portable if you use them
Could you provide a link or some examples to qualify this, please?
 
Old 10-16-2003, 06:48 AM   #5
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
istringstream and ostringstream are part of the c++ standard library and definatly should be used, i think there is a problem with strstream which might be what your thinking of but certanly istringstream and ostringstream are great and definatly should be used.
 
Old 10-16-2003, 06:59 AM   #6
UltimaGuy
Member
 
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 32
Yes, I am sorry. I confused strstreams with istringstreams. SORRY!
 
Old 10-16-2003, 08:59 AM   #7
dakensta
Member
 
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194

Rep: Reputation: 35
No worries :-)

Just trying to keep explanations clear for future reference (LQ seems to turn up on google for at least 50% of my Linux queries now).

strstream is indeed deprecated now - various problems I know of included:

no null terminated string returned from str() unless inserted,
the ability to use programmer allocated buffer (inconsistent),
and the need to block access to the underlying buffer to get the string and unblock to insert / extract again.

I guess it was just too confusing - I am pretty sure there is a section on this in Josuttis (my copy is at home right now, I am not).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration