So I received some code and a memo saying, I quote, "problems with overflows". I check it out, and I see something along the lines of the following:
char cmdstr; sprintf_s(cmdstr,"STAS %d,%d\n",min(m_fstart,m_fstart2),max(m_fstop,m_fstop2)); viPrintf(vi,cmdstr); viPrintf(vi,"CHAN1\n"); // ---SNIP---
Immediately, I changed it to this:
std::stringstream cmdstr; cmdstr << "STAS " << min(m_fstart,m_fstart2) << "," << max(m_fstop,m_fstop2) << std::endl; viPrintf(vi,cmdstr.str().c_str()); // viPrintf is not const-correct, i.e. cmdstr is declared as "char*", not "const char*"
HOWEVER, as stated in the comments above, the function "viPrintf" is not const correct. Even though it only reads form "cmdstr", the function argument was declared as "char*" and the compiler will refuse to compile it.
I cannot change viPrintf because it is part of an external library I don't have access to.
How can I go about converting a string stream to a non-const char array? The thought of copying it into a new std::string object and using &str.at(0) crossed my mind, but that seems a little... I don't know, is there a better way?
Edited by TheComet, 04 February 2014 - 06:19 AM.