c-str

    0热度

    2回答

    我有这样的代码块,写成strstream。我将它转换为sstream如下。我不确定,但我认为printStream->str()正在返回一个字符串对象,其中包含printStream所指向的流缓冲区中的内容的副本(临时),然后您将调用c_str()并获取const char *,然后投射该常量,然后将该指针返回到函数作用域之外。我认为,因为您从printStream->str()得到的临时值,您将

    0热度

    1回答

    我使用Qt Creator和验证码: string execpath = ""; execpath += (QCoreApplication::applicationDirPath()).toStdString(); WinExec("ffmpeg -f dshow -t 32 -i audio=\"virtual-audio-capturer\" -y "+(execpath.c_str()

    0热度

    1回答

    我在为MSVCC/Windows编写的项目上工作,我必须移植到GCC/Linux。该项目有它自己的字符串类,它将数据存储在Qt的QString中。另外,为了转换为wchar_t *这里原是该方法(适用于Windows): const wchar_t* String::c_str() const { if (length() > 0) { return (const

    2热度

    2回答

    这是关于处理std::string的const副本的STL实现之间的区别的问题。我有这样简短的测试,它不通过c_str()回到2常量复印和打印地址: #include <stdio.h> #include <string> using namespace std; int main() { string a("Hello World!"); const string

    3热度

    2回答

    我正在设计一个模拟shell程序,我不能完全模仿“cd”命令。我试过chdir(),但那不起作用,所以我继续试图改变环境变量“PWD =” 这是我的,我想这可能是接近的。 (请,请,纠正我,如果我错了,或者是被chdir更密切()) else if (command == "cd") { string pathEnv = "PWD="; string new

    1热度

    1回答

    我不知道是否有一种方法,以避免在这种情况下,使用临时字符串: tempString = inputString.substr(commaLast,commaCurrent-1); yPos = strtod(tempString.c_str(), NULL); 没有办法使用SUBSTR命令,并没有先存储在临时串子返回c_str (假设我不想修改原始字符串)。

    2热度

    3回答

    让我先感谢您花时间阅读本文。 我想读C++中的文件。目前我有一个方法允许用户在浏览器中选择一个文件,并将其作为'std :: string'返回。然后我必须打开这个文件,但是我为此使用的方法使用了const char *。所以我需要从一个转换到另一个。 如果在Windows中使用字符串读取文件时有一个简单的方法,那么让我知道它会解决我的整个问题。 当我从字符串转换为const char *时,使用

    1热度

    1回答

    我有一个问题,我无法自己修复。 string filenameRaw; filenameRaw= argv[1]; function(filenameRaw.c_str(),...); function(const char* rawDataFile,const char* targetfieldFile,const char* resultFile,const char* filenam

    2热度

    4回答

    下面是代码: string fname = "/home/jack/example.csv"; ifstream csvin(fname.c_str()); if (csvin.eof()) { do_something; } 我的问题是:在什么情况下eof()返回true。我有以下选项: 文件不存在。 文件为空。 文件不存在或为空。 不幸的是documentation没有帮助

    2热度

    5回答

    用C++我想实现我的类的toString()函数: void ClassName::toString(string& returnString) { sprintf(returnString.c_str(), "Position: (%f, %f, %f)\n", position.x, position.y, position.y); } 不过,我不断收到此错误:类型为cons