如何初始化字符串指针? [英] how to initialize string pointer?

查看:277
本文介绍了如何初始化字符串指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想存储静态值在字符串指针是否可行?

I want to store the static value in string pointer is it posible?

如果我喜欢

string *array = {"value"};

发生错误

error: cannot convert 'const char*' to 'std::string*' in initialization


推荐答案

您将需要写

string *array = new string("value");

虽然你最好使用

string array = "value";

,因为这是使用它的预期方式。否则你需要跟踪记忆。

as that is the intended way to use it. otherwise you need to keep track of memory.

这篇关于如何初始化字符串指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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