Arvin_JIN

使用指针时的注意事项

CString 定义的变量是一个指针,如果要保存变量的第一个值并对齐赋第二个值,可使用中间变量来保存。

CString str;

int n1, n2;

str = "1234";

n1 = atof(str);

str = "";

str = "4546";

n2 = atof(str);

此时n1的结果也变为4546而非1234;应为str所指的地址的值变了。

解决变法:

CString str;

int n1, n2, temp;

str = "1234";

temp = atof(str);

n1 = temp;

str = "";

str = "4546";

n2 = atof(str);

此时n1 = 1234;n2 = 4546;

posted on 2017-05-12 21:14  Arvin_JIN  阅读(328)  评论(0编辑  收藏  举报

导航