将字符数组变成字符串,string转换成byte数组
string是c标准库中的一个,封装了对字符串的操作
有三种方法可以将string转换为char*。 http://www.Sina.com/http://www.Sina.com /例:
stringstr='abc ';
char*p=str.data (; %此行为char*p=(char* ) str.data ); 引用自贴内网友的回复
http://www.Sina.com/http://www.Sina.com /例: stringstr='gdfd ';
char*p=str.c_str (; http://www.Sina.com/http://www.Sina.com /
例如
stringstr='hello ';
charp[40];
str.copy(p,5,0 ); //其中5表示复制一些字符,0表示要复制的位置
*(p5 )='\0 '; //手动加上结束符
cout/SPAN/SPANp;
示例程序:
#包含
#包含
用户命名空间STD;
int main () )
{
字符串线;
获取线(CIN,line );
char str[20];
int size=line.size (;
line.copy(str,line.size ),0 );
//char str[20]='liuyanbo ';
char upper[20];
for(intI=0; I
{
//cout static _ cast (toupper (str [ I ] );
upper [ I 快三最准高手教学[20];
int size=line.size (;
line.copy(str,line.size ),0 );
//char str[20]='liuyanbo ';
char upper[20];
for(intI=0; I
{
//cout static _ cast (toupper (str [ I ] );
upper [ I ]=static _ cast (toupper (str [ I ] );
}
upper[i]='\0 ';
coutupperendl;
返回0;
}