小编san*_*ndy的帖子

sprintf格式化double值

在UNIX 中将double值转换为字符串时,我有一个特定的问题sprintf().

例如,我有两个值:

double a = 0.009984354523452;
double b = 0.01;
Run Code Online (Sandbox Code Playgroud)

转换时,我正在使用:

sprintf(somestringvar, "Double value : %.15f \n", a);
sprintf(diffstringvar, "Double value : %.15f \n", b);
Run Code Online (Sandbox Code Playgroud)

转换为字符串.

我的问题是'a',值正确打印但是对于'b'的值,在尾端附加0.请提供任何常用的方法来表示'a'和'b'作为确切的值.

c c++ unix printf

5
推荐指数
1
解决办法
2万
查看次数

新标准库字符串放置中的内存泄漏

我在标准库字符串的新位置面临内存泄漏.

下面我给出了泄漏显示的代码.

string string1("new string");
char _string[sizeof(string)];
new(_string) string(string1);
Run Code Online (Sandbox Code Playgroud)

使用dbx找到泄漏,如下所示

Actual leaks report    (actual leaks:            1  total size:         52 bytes)

  Total     Num of  Leaked     Allocation call stack
  Size      Blocks  Block
                    Address
==========  ====== =========== =======================================
        52       1    0x43f68  operator new < std::basic_string<char,std::char_traits<char>,std::allocator<char> >::__getRep < std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string < main


Possible leaks report  (possible leaks:          0  total size:          0 bytes)
Run Code Online (Sandbox Code Playgroud)

这是真正的内存泄漏还是dbx将其表示为泄漏?

c++ linux solaris

2
推荐指数
1
解决办法
704
查看次数

标签 统计

c++ ×2

c ×1

linux ×1

printf ×1

solaris ×1

unix ×1