c++ - 如何将char字符串转换为std字符串

标签 c++

我有以下代码,我不知道如何将char字符串转换为std字符串。有人可以帮我吗?

char Path[STRING_MAX];
test->getValue(Config::CODE,Path);

size_t found;
cout << "Splitting: " << Path << endl;
found=Path.find_last_of("/");
cout << " folder: " << Path.substr(0,found) << endl;
cout << " file: " << Path.substr(found+1) << endl;

最佳答案

用这个:

std::string sPath(Path);

要么:
std::string sPath = Path;

要么:
std::string sPath;
sPath.assign(Path);

关于c++ - 如何将char字符串转换为std字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5556543/

相关文章:

c++ - 正确使用递归

c++ - C++ 中的多线程 SDL 错误

c++ - 无法在 Ubuntu 上将共享库与 Eclipse 链接

c++ - 字符数组顺序错误

c++ - MD5 散列时填充字符串

c++ - 在大型 Json 文件中查找文本

c++ - 为什么我的指针在 C++ 中变成了悬空指针?

c++ - 添加鼠标事件来改变简单圆圈的颜色

c++ - Qt 5.0 [ui_mainwindow.h] 错误-1073741515

c++ - 当我尝试从我的数组中打印一个字符串时,它不起作用 (C++)