替换CString元素 [英] Replacing CString elements

查看:185
本文介绍了替换CString元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想原谅自己,如果我的问题可能很蹩脚,我还是学生,

所以我正在制作一个计算器,问题出现时a

浮点值在对话框中输入(作为CString),带有,

如何用。替换它。并将其转换为双倍?


我的CString是testStr(" 123,54")我想让它加倍d = 123.54

我正在使用VS 6.0

Hi,
I want to excuse myself if my question may be lame, I am still a student,
So I am making a calculator and the problem appears when a
float value is entered in the dialog box (as CString) with ","
How can I replace it with "." and covert it to double?

My CString is testStr("123,54") I want to make it double d=123.54
I am using VS 6.0

Thanks in advance!

推荐答案


你好,

我想原谅自己,如果我的问题可能很蹩脚,我还是学生,

所以我正在制作一个计算器,问题出现在

浮点值在对话框中输入(作为CString),带有,

如何用。替换它。并将其转换为双倍?


我的CString是testStr(" 123,54")我想让它加倍d = 123.54

我正在使用VS 6.0


提前致谢!
Hi,
I want to excuse myself if my question may be lame, I am still a student,
So I am making a calculator and the problem appears when a
float value is entered in the dialog box (as CString) with ","
How can I replace it with "." and covert it to double?

My CString is testStr("123,54") I want to make it double d=123.54
I am using VS 6.0

Thanks in advance!



因为字符串实际上是字符数组,所以你需要搜索,,上诉

,然后将其替换为。


Savage

Because strings are in fact arrays of chars,you need to serach for "," apperance
and then replace it with "."

Savage


将其转换为double可能是但是更难 - 可能在一些不起眼的库中定义了一个函数。我知道函数atoi()将char(或char数组?)转换为整数 - 也许有浮点数的atof()或atod()函数。
Converting it to a double may be harder, though - there may be a function defined in some obscure library. I know the function atoi() converts a char (or char array?) to an integer - maybe there is an atof() or atod() function for floating point numbers.


是的喜欢Gannon 11说有一个函数atof();并且它具有以下语法:
double atof(const char * s);


并且还有一个函数

long double _atold(const char *(s)); ,转换为long double;



你也可以使用strtod 。


strtod类似于atof,但它提供了比atof()更好的错误检测;


这是语法:

double strtod(const char * s,char ** endptr);


注意:如果endtpr不为null,则此函数设置为* endtpr指向停止扫描的char。(这对于错误检测很有用)


Savage
Yes like the Gannon 11 said there is a function atof(); and it has the following syntax:
double atof( const char *s);

and there is also a function

long double _atold(const char *(s));,which converts to long double;


You could also use strtod.

strtod is similiar to atof,but it provides better error detection than atof();

Here is the syntax:

double strtod(const char *s,char **endptr);

Note:If endtpr is not null,this function set *endtpr to point to the char that stoped scan.(This is usefull for error detection)

Savage


这篇关于替换CString元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆