[英]C++ SNAP Library convert std::string to TStr
In the SNAP Library there's a method that allows me to save a file in my pc here it is: 在SNAP库中,有一种方法可以让我在PC中保存文件,方法是:
TSnap::SaveEdgeList(G, q, "Edge list format");`
in this function the 2nd argument its type is TStr
which represents string types in SNAP library 在此函数中,第二个参数的类型为
TStr
,它表示SNAP库中的字符串类型
I have a string variable that contains a full directory of where I want to put my file like this: 我有一个字符串变量,其中包含一个完整目录,该目录将我的文件放置在这样的位置:
string filedir = openFileDialog1->FileName;
What I want to do is to give the content of a string variable to a TStr
variable like this: 我想要做的是将字符串变量的内容提供给
TStr
变量,如下所示:
TStr q = filedir;
But unfortunately it gives an error. 但不幸的是,它给出了一个错误。 So i was wondering if anyone has an alternative solution or something Thank you
所以我想知道是否有人有替代解决方案或其他东西谢谢
Quick googling revealed that TStr
can be constructed from a C-string via TStr(const char* CStr)
constructor. 快速谷歌搜索揭示,
TStr
可从C-串经由被构建TStr(const char* CStr)
构造。
So, following will work: 因此,以下将起作用:
TStr q = filedir.c_str();
Alternatively, you can pass filedir.c_str()
directly as an argument. 或者,您可以直接将
filedir.c_str()
作为参数传递。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.