C ++设置字符的值** [英] C++ Set value for a char**
问题描述
我试图为 char **
变量赋值。在我的 foo.h
中,我定义了一些变量,例如
I'm trying to assign a value to a char**
variable. In my foo.h
I've defined a couple of variables such as
#define APIOCTET int
#define APILONG long
#define APICHAR char
#define APISTRING char*
现在在 foo.cpp
我是tryng使用一个方法,其中
Now in my foo.cpp
I'm tryng to use a method where
APILONG apiInitialize(APISTRING filePath, APISTRING* outputString)
{
//open text file to where output will be printed
//do other stuff, etc..
//return result;
}
我想为我的 APISTRING * outputString
但我只是不知道如何这样做,我尝试了很多基本上是以下代码的变体
I'd like to assign a value to my APISTRING* outputString
but I just can't figure out how to do so, I've tried many things which are basically a variation of the following code
APISTRING error = "error";
APISTRING other = "string";
APISTRING charArr[] = { error, other, error };
APISTRING *charArr2[] = { charArr };
errorString = *charArr2;
也不是100%清楚什么是 APISTRING * outputString
。当我尝试编译它给我一个错误消息,它提到它是一个
char **
。是一个二维数组吗?指向字符数组的指针?但最重要的是,我该如何为这个变量赋值呢?先感谢。
Also im not 100% clear on what exactly is APISTRING* outputString
. When I try to compile it gives me an error message where it mentions it's a char**
. Is it a 2D array?.. A pointer to an array of chars?.. But most importantly, how would I assign a value for this variable? Thanks in advance.
推荐答案
APISTRING *是指向char的指针。
The APISTRING* is a pointer to a pointer to char. It holds an address which holds the address of the first character of the string in memory.
See this question for more info on double pointers in C/C++.
要分配给您需要做的字符串,请使用C / C ++中的双指针更多信息的5814646 / c-double-pointer * outputString =string
To assign to the string you would need to do *outputString = "string"
这篇关于C ++设置字符的值**的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!