Changing double to character string in C++


 
Thread Tools Search this Thread
Top Forums Programming Changing double to character string in C++
# 1  
Old 02-06-2014
Changing double to character string in C++

I want to convert an double to a character string. I done the integer and float ones using itoa and ftoa. How can I do a similar thing with doubles?

Code:
String::String
(
 const float  f
 ) {

  char *cdata = ftoa (f);
  strcpy (STR, cdata.c_str ());

}

String::String
(
 const double  d
 ) {

}

# 2  
Old 02-06-2014
snprintf can work for many different types:

Code:
char buf[512];

// float casts to double when passed here, so %f works for double and float
snprintf(buf, 512, "%f", floattype);  
snprintf(buf, 512, "%f", doubletype);

// These are the same in 32-bit systems and different in 64-bit.
snprintf(buf, 512, "%d", inttype);
snprintf(buf, 512, "%ld", longtype);

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed searches a character string for a specified delimiter character, and returns a leading or traili

Hi, Anyone can help using SED searches a character string for a specified delimiter character, and returns a leading or trailing space/blank. Text file : "1"|"ExternalClassDEA519CF5"|"Art1" "2"|"ExternalClass563EA516C"|"Art3" "3"|"ExternalClass305ED16B8"|"Art9" ... ... ... (2 Replies)
Discussion started by: fspalero
2 Replies

2. Shell Programming and Scripting

Replace double quotes with a single quote within a double quoted string

Hi Froum. I have tried in vain to find a solution for this problem - I'm trying to replace any double quotes within a quoted string with a single quote, leaving everything else as is. I have the following data: Before: ... (32 Replies)
Discussion started by: pchang
32 Replies

3. Shell Programming and Scripting

Changing paragraph to a width of 80 character

I have the following text file and want to change the paragraphs so that they fill 80 characters rather than the usual 65 in this case. Is there an easy way to do this? All three groups were distinguished by the remarkable manner in which they moved about on the solar surface, not only in... (7 Replies)
Discussion started by: kristinu
7 Replies

4. Shell Programming and Scripting

Changing the character after the Underscore(_)

Hi Everyone, I am looking for a command that would do the following: 1) Change all the letters/words in a file to Lower case Letters/words. 2) Remove the Underscore (_) and Change the Character after the underscore (_) to an Uppercase letter. Example: File contains the below words: ... (5 Replies)
Discussion started by: filter
5 Replies

5. Shell Programming and Scripting

Changing a string in multiple files

New to scripting and unix. Would like to know how to change a string in a file. eg: From network=/usr/spool/progs/ to network=/spool/progs/ In multiple files. (4 Replies)
Discussion started by: smcraesun
4 Replies

6. Shell Programming and Scripting

Removal of new line character in double quotes

Hi, Could you please help me in removal of newline chracter present in between the double quotes and replacing it with space. For example ... Every field is wrapped with double quotes with comma delimiter, so I need to travese from first double quote occerence to till second double... (7 Replies)
Discussion started by: vsairam
7 Replies

7. Shell Programming and Scripting

Korn: How to loop through a string character by character

If I have a string defined as: MyString=abcde echo $MyString How can I loop through it character by character? I haven't been able to find a way to index the string so that I loop through it. shew01 (10 Replies)
Discussion started by: shew01
10 Replies

8. UNIX for Advanced & Expert Users

How to remove a character which is enclosed in Double quotes

I want to remove the comma which is present within the double quoted string. All other commas which is present outside double quotes should be present. Input : a,b,"cc,dd,ee",f,ii,"jj,kk",mmm output : a,b,"ccddee",f,ii,"jjkk",mmm (3 Replies)
Discussion started by: mohan_tuty
3 Replies

9. UNIX for Advanced & Expert Users

How can I use double character delimiter in the cut command

Hi All, Can the cut command have double character delimiter? If yes, how can we use it. if my data file contains : apple || mango || grapes i used cut -f1 -d"||" filename but got an error. Plz help.... Thanks. (1 Reply)
Discussion started by: AshishK
1 Replies

10. Programming

converting character string to hex string

HI Hi I have a character string which contains some special characters and I need it to display as a hex string. For example, the sample i/p string: ×¥ïA Å gïÛý and the o/p should be : D7A5EF4100C5010067EFDBFD Any pointers or sample code pls. (5 Replies)
Discussion started by: axes
5 Replies
Login or Register to Ask a Question