简体   繁体   中英

Why am I able to read char[2] but not char[1]?

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

Does anyone have any idea why?

(oracle data type is char(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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM