在c ++中的strcpy的替代 [英] Alternative of strcpy in c++

查看:258
本文介绍了在c ++中的strcpy的替代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C i中,使用 strcpy 制作字符串的深度复制,但仍然是'fine'在C ++中使用 strcpy 或者有更好的替代品,我应该使用而不是?

In C i used strcpy to make a deep copy of a string, but is it still 'fine' to use strcpy in C++ or are there better alternatives which i should use instead ?

推荐答案

在C ++中,最简单的方法是使用std :: string类而不是char *。

In C++ the easiest way is usually to use the std::string class instead of char*.

#include <string>
...
  std::string a = "Hello.";
  std::string b;
  b = a;

行b = a;做同样的事情你通常用strcpy。

The line "b = a;" does the same thing you would usually do with strcpy.

这篇关于在c ++中的strcpy的替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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