LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-22-2007, 07:14 PM   #1
americanforest
LQ Newbie
 
Registered: Sep 2007
Posts: 19

Rep: Reputation: 0
C++ String to double conversion


Say I have a number in a string (Y) in the form "XXX.XXXXX". It seems that (char*)Y.data() stops at the decimal point. Is there any way to change the delimiter settings so that it gets the decimal too?
 
Old 10-22-2007, 07:19 PM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Code:
#include <sstream>
#include <string>
int main()
{
   std::string str("123.123");
   std::stringstream sstr;
   sstr <<str;
   double d;
   sstr >>d;
}
Hmm have I misunderstood your question?
You have a string and want to copy it to another string?

Last edited by dmail; 10-23-2007 at 10:16 AM. Reason: Oops fixed
 
Old 10-23-2007, 06:50 AM   #3
americanforest
LQ Newbie
 
Registered: Sep 2007
Posts: 19

Original Poster
Rep: Reputation: 0
Using your code it tells me that there is no such file when I try to include <stringstream> and compile using g++. What's up with that?
 
Old 10-23-2007, 07:29 AM   #4
Hivemind
Member
 
Registered: Sep 2004
Posts: 273

Rep: Reputation: 30
Because it should be <sstream>.
 
Old 10-23-2007, 09:44 PM   #5
americanforest
LQ Newbie
 
Registered: Sep 2007
Posts: 19

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Hivemind View Post
Because it should be <sstream>.
Thanks. Works now.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in string to float conversion..C++ fs11 Programming 3 01-15-2007 06:28 PM
C++ string to integer conversion fatman Programming 6 06-18-2006 08:17 AM
c++: float to double conversion ashirazi Programming 6 11-30-2004 04:14 PM
string to double cynthia Programming 4 10-12-2004 02:40 AM
double conversion Xiangbuilder Programming 15 10-09-2003 09:12 AM

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

All times are GMT -5. The time now is 07:08 PM.

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