在C ++中将String转换为Cstring [英] Converting String to Cstring in C++

查看:116
本文介绍了在C ++中将String转换为Cstring的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要转换的字符串, string = apple 并想将其放入这种样式的C字符串中, char * c ,其中包含 {a,p,p,l,e,'\0'} 。我应该使用哪种预定义方法?

I have a string to convert, string = "apple" and want to put that into a C string of this style, char *c, that holds {a, p, p, l, e, '\0'}. Which predefined method should I be using?

推荐答案

.c_str()返回 const char * 。如果需要可变版本,则需要自己制作一个副本。

.c_str() returns a const char*. If you need a mutable version, you will need to produce a copy yourself.

这篇关于在C ++中将String转换为Cstring的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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