c++ - 如何将 `const char *GetVersion()`(来自第三方库)分配给变量?

标签 c++ string pointers

如何将变量赋给 const char *GetVersion() 的值?

我正在使用第三方库,该库声明 const char *GetVersion() 可用。下面的代码编译成功:

#include <iostream>
#include <Windows.h>
#include "ThirdPartyLibrary.h"

int main()
{
    const char *GetVersion();
}

如何将 const char *GetVersion() 赋值给一个变量?

更新

char const *GetVersion()

The version of the Application manual interface that has loaded the running extension. This version is distinct from the API version, which is documented in Macros , below.

最佳答案

你的代码编译因为编译器理解

const char *Function();

作为一个函数原型(prototype)


首先,阅读文档。看起来你可以简单地写

const char* my_variable = Function();

但是请检查您是否需要释放任何内存。 (我的直觉是你没有给定返回类型是 const,但也许你需要回调到那个库中传递 my_variable 作为参数)。

关于c++ - 如何将 `const char *GetVersion()`(来自第三方库)分配给变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46151860/

相关文章:

c++ - 类中字符串成员变量的语法错误

c - 显示来自正在传递的 Struct 的数据

c++ - 在 C++ 中包含 C header ,同时保持功能

c++ - CListCtrl 报 TableView 中没有颜色

javascript - 如何获取指定字符的位置?

c# - 为什么 bigint 数字不与 c# CultureInfo 分割?

c - 为什么我们不能在 C 中通过引用传递指针?

c - 打开文件会导致 sYSMALLOc 断言失败

c++ - 具有扩展字符 (128-255) 的 Linux 中的 open() 函数返回 -1 错误

c++ - 返回 std::vector 时不调用复制构造函数