gpt4 book ai didi

c++ - Qt - C++ 字符串连接段错误

转载 作者:行者123 更新时间:2023-11-28 08:00:32 25 4
gpt4 key购买 nike

我是 C++ 新手,所以我想我掉进了 C++ 新手陷阱。

我尝试执行以下操作:

QString  sdkInstallationDirectory=getenv("somEnv");

QString someSourceDir=sdkInstallationDirectory+"\\Data\\"+someReference+ "\\src";

我遇到了段错误。

我猜这是因为 const 字符的连接和分配给 someSourceDir QString 的内存不足。

我的错误到底是什么?我怎样才能做这个连接?

最佳答案

char * getenv ( const char * name );

A null-terminated string with the value of the requested environment variable, or NULL if that environment variable does not exist.

为什么不检查结果?

编辑。

因此,不需要检查指针。

For historical reasons, QString distinguishes between a null string and an empty string. A null string is a string that is initialized using QString's default constructor or by passing (const char *)0 to the constructor.

关于c++ - Qt - C++ 字符串连接段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11611438/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com