converting problem

ltdtombs isn't working.i take this error "cannot convert `std::basic_string<char, std::char_traits<char>, std::allocator<char> >' to `char*' in assignment "i want to convert long double to char*
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#include <cstring>
#include <string>
#include <sstream>

using namespace std;
//////////////////////////////////
class bMoney
{
      private:
         long double money;
         int n;
         char* end;
         int len;
         char string[100];
         char* karakter;
      
      public:
             
       bMoney(): money(0.0),n(0),len(0)
       { }
       ///////////////////////////
       void getMoney()
       {
       
      cout << "Enter money: "; 
      cin >> string;
      }
      //////////////////////////
      void putMoney()
      {cout <<"Your cash is:" << money << end;}
      ////////////////////////////////////////////////////////////
      long double mstold(char para[])
      {
          int n=0;
          char karakter[100];
          char* end;
          int len = strlen(string);
                 for(int i=0; i<len+1; i++)    
                 {
                      if(string[i] >= '0' && string[i] <= '9')
                      {
                        karakter[n] = string[i];
                        n++;
                      }
                 }
     
                        
               money = strtold(karakter,&end);
     
               return money;
      }
        
///////////////////////////////////////////////////////
       void ldtombs()
        {
         std::ostringstream ss;
         ss << money;
         karakter = ss.str();
         }
};
            

   
int main(int argc, char *argv[])
{  

    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

karakter = strdup( ss.str().c_str() );

and then you have to free( karakter ) when you are done with the memory
And why do you include
stdlib.h
and
cstdlib
in the same program? They're both identical, except that the first one is non-standard.
thank your answers.@jsmith where does come c.str() ?.
@Qwertyman thank you. i choice stdlib.h because thats nice :)
c_str() is a std::string member function: http://www.cplusplus.com/reference/string/string/c_str/
cool thank you again
i choice stdlib.h because thats nice :)

???
stdlib.h more content than cstdlib
According to this site it doesn't: http://www.cplusplus.com/reference/clibrary/cstdlib/
Look at the title when you open the link.

As QWERTYman said, you should use cstdlib as stdlib.h is non-standard for C++.
Last edited on
stdlib.h is the C header
cstdlib is the C++ header
If you are programming in C++ use cstdlib
ok.thank u
Topic archived. No new replies allowed.