问一个菜菜的问题,请大家帮助回答。

newlight 2003-07-10 06:16:47
把普通字符串转换成string类的对象,怎么做?相反string类的对象转换成普通字符串怎么转换??

谢谢大家~~!!!!
...全文
21 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
newlight 2003-07-10
  • 打赏
  • 举报
回复
呵呵,要不说是一个菜菜的问题
zteliubin 2003-07-10
  • 打赏
  • 举报
回复
up,完全是捡分。
WebDB 2003-07-10
  • 打赏
  • 举报
回复
字符串转换为string:


char ch[10] = "abcde";
string str(ch);
或者:string str = ch;

string 转换为 字符串

string str("abcde");
char ch[10];
memset( ch, 0, 10);
strcpy (ch, str);
newlight 2003-07-10
  • 打赏
  • 举报
回复
哦,我去试试, point_to(一 指) 谢谢了!!!
point_to 2003-07-10
  • 打赏
  • 举报
回复
#include <string>
#include <iostream>
using namespace std;
#include "stdio.h"

void main()
{

char ca[10]="abcdef";
string str1=ca;
string str2(ca);
cout<<str1<<" ";
cout<<str2<<endl;

string str="abcdefgh";
const char *ps=str.c_str();
cout<<ps<<endl;
//如果写入数组,要在最后加上'\0'结束符


}

leasun 2003-07-10
  • 打赏
  • 举报
回复
string(const char *)
string.c_str()
string.copy

70,035

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧