社区
C语言
帖子详情
char to string???? string to double!??
cenpy
2002-07-27 10:22:41
(1)char怎样变为string型!
如:
string gg;
char q='p';
gg=q.ToString();
cout<<gg;
报错!
(2)
还有string g="3.40";
怎样判断3.40是double或者int并把他转化为int或double呢!?
每题个50分!!
...全文
959
9
打赏
收藏
char to string???? string to double!??
(1)char怎样变为string型! 如: string gg; char q='p'; gg=q.ToString(); cout<<gg; 报错! (2) 还有string g="3.40"; 怎样判断3.40是double或者int并把他转化为int或double呢!? 每题个50分!!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
9 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
tigerfox
2002-07-28
打赏
举报
回复
CTR Function
sprintf()
atoi() itoa()
atof()
cenpy
2002-07-28
打赏
举报
回复
to winco(老狼):程序改為如下時,有變化
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main()
{
int i;
float j;
char* g="t3";
i=atoi(g);
j=atof(g);
if((float)i==j)
cout<<"int"<<endl;
else
cout<<"float"<<endl;
return 0;
}
輸出結果是:int
但是“t3”詩歌變量
我想應該加上這個:
for(int i=0;i<g.lengh();i++)
if(g[i]<'0'||g[i]>'9')
cout<<"variable Value!";
但是g.lengh()怎樣得到?〉g的長度怎樣得到?
另外,我想要string型來做!應該怎樣 !〉因爲我上面的程序都用了 string了!而且string型比較簡單!
winco
2002-07-28
打赏
举报
回复
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main()
{
int i;
float j;
char* g="3.50";
i=atoi(g);
j=atof(g);
if((float)i==j)
cout<<"int"<<endl;
else
cout<<"float"<<endl;
return 0;
}
cenpy
2002-07-28
打赏
举报
回复
好!不过你的代码好象写错了!
kwok_1980
2002-07-28
打赏
举报
回复
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main()
{
int i;
float j;
char* g="3.50";//应该使用char*类型吧!atoi,atof等使用的是地址(指针)
i=atoi(g); //并不用你去担心,函数会自动转换相应的类型
j=atof(g);
cout<<i<<endl; //3 函数会吧小数点后的数截去,只留下整数部分
cout<<j<<endl; //3.5
return 0;
}
kwok_1980
2002-07-28
打赏
举报
回复
#include <iostream>
#include <string>
using namespace std;
int main()
{
string gg;
char q='p';
gg=q; //其实并不用ToString(),直接就可以赋值!
cout<<gg<<endl; //试试吧!VC6.0可以通过!
return 0;
}
liushmh
2002-07-28
打赏
举报
回复
int isnumber(string g)
{
for (int i=0;i<g.size();++i)
{
if(i>=1)
{
if(i<'0'||i>'9'&&i!='.') return 0;
}
if(i==0)
{
if(i<'0'||i>'9')return 0;
}
}
return 1;
}
1表示是数字
0表示非数字
cenpy
2002-07-28
打赏
举报
回复
但是怎样判断是为double型啊!?
如:3.44和e344两个数!一个是double型一个是变量!
能判断了才能知道转化为什么类型啊!
cenpy
2002-07-27
打赏
举报
回复
没有人回答吗?!
还是没有人懂!?
MySQL 数据类型和运算符
============================= # 数据类型 整数类型:五种 TINY SMALL MEDIUM INT BIG 浮点和定点小数类型:三种 FLOAT
DOUBLE
DECIMAL 日期与时间数据类型:五种 YEAR -1 字符串类型:二种
CHAR
(M) VAR
CHAR
(M) -1 ...
string
转换为
string
java,在Java中如何将
String
转换为
char
或
char
转换为
String
?
Is there a way to turn a
char
into a
String
or a
String
with one letter into a
char
(like how you can turn an int into a
double
and a
double
into an int)? (please link to the relevant documentation if...
Java
char
转换为
String
,
String
转换为
char
数组
Today we will look into java
char
to
String
program. We will also learn how to convert
String
to a
char
array. 今天,我们将研究java
char
to
String
程序。 我们还将学习如何将
String
转换为
char
数组。 Java...
java中
String
和
char
(面试必考题)
一
char
和
string
的区别: 1
char
是表示的是字符,定义的时候用单引号,只能存储一个字符。例如;
char
='d'. 而
String
表示的是字符串,定义的时候用双引号,可以存储一个或者多个字符。例如:
String
=“we are ...
C++:
string
to
double
C++ Convert
String
to
Double
Speed (There is also a
string
-to-int performance test.) A performance benchmark of which method is faster of converting an std::
string
to a
double
. The goal is ending up ...
C语言
69,378
社区成员
243,075
社区内容
发帖
与我相关
我的任务
C语言
C语言相关问题讨论
复制链接
扫一扫
分享
社区描述
C语言相关问题讨论
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章