Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Proper way to obtain a std:string from a Pro*C/C++ VARCHAR

What is the proper way of getting a std:string out of a Pro*c/C++ VARCHAR?

If I try either of the following, g++ complains:

VARCHAR some_column[10];

std::string x(std::string(reinterpret_cast<char const*>(some_column.arr), some_column.len);
std::string y((char const*) some_column.arr, some_column.len);

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Basically you can’t.

Read it into a character array which is big enough to hold the value.
Add one additional character to the array size, and initialize it to 0, so that you have a c string.

After loading it, into the character buffer, assign it to the string.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading