为什么我能读取char [2]但不能读取char [1]?

时间:2022-08-24 21:47:15

I am able to read char into char[2] in OCI C++ code, but I am not able to read to char1?

我能够在OCI C ++代码中将char读入char [2],但我无法读取到char1?

Does anyone have any idea why?

有谁知道为什么?

(oracle data type is char(1))

(oracle数据类型为char(1))

2 个解决方案

#1


If the input is being treated like a string, then room is needed to apply the null-termination (a '\0') at the end. That is if the data is 'a', then the string representation ("a") is stored in memory as two characters 'a' and '\0'. The '\0' is needed to tell the usual string processing suspects where the string ends.

如果输入被视为字符串,则需要空间来在末尾应用空终止('\ 0')。也就是说,如果数据是'a',则字符串表示(“a”)作为两个字符'a'和'\ 0'存储在存储器中。需要'\ 0'来告诉字符串结束的常用字符串处理嫌疑人。

Without knowing anything about the tools you're using I can't say for sure, but you might be able to assign to a character variable (as opposed to a character array variable).

在不知道你正在使用的工具的情况下我无法确定,但你可能能够分配给一个字符变量(而不是字符数组变量)。


Looking briefly at the docs along the link you posted, I suspect that you should be using std::string as the receiving type for textual data.

简要地看一下你发布的链接上的文档,我怀疑你应该使用std :: string作为文本数据的接收类型。

#2


Possibly you need space for the null character at the end of the string?

可能你需要在字符串末尾的空字符空间?

#1


If the input is being treated like a string, then room is needed to apply the null-termination (a '\0') at the end. That is if the data is 'a', then the string representation ("a") is stored in memory as two characters 'a' and '\0'. The '\0' is needed to tell the usual string processing suspects where the string ends.

如果输入被视为字符串,则需要空间来在末尾应用空终止('\ 0')。也就是说,如果数据是'a',则字符串表示(“a”)作为两个字符'a'和'\ 0'存储在存储器中。需要'\ 0'来告诉字符串结束的常用字符串处理嫌疑人。

Without knowing anything about the tools you're using I can't say for sure, but you might be able to assign to a character variable (as opposed to a character array variable).

在不知道你正在使用的工具的情况下我无法确定,但你可能能够分配给一个字符变量(而不是字符数组变量)。


Looking briefly at the docs along the link you posted, I suspect that you should be using std::string as the receiving type for textual data.

简要地看一下你发布的链接上的文档,我怀疑你应该使用std :: string作为文本数据的接收类型。

#2


Possibly you need space for the null character at the end of the string?

可能你需要在字符串末尾的空字符空间?