tags:

views:

68

answers:

1
void EDataset::PrintErr(const NDataString& ErrMsg){       
   system("echo " + $ErrMsg + "  >> err.txt");
   .... code ....
}

It prints blank line as the value of ErrMsg. How come?

A: 

As already @gf mentioned in the comment, $ErrMsg is not proper. Also, NDataString definition is not clear.

Assuming there is a way to get string out of NDataString :

void PrintErr(const NDataString& ErrMsg)
{      
    std::stringstream tempString;
    tempString <<"echo ";
        //Get the string out of NDataString... 
        //if ErrMsg was std::string then c_str() will give you const char*
    tempString<< ErrMsg.c_str();  
    tempString<<"  >> err.txt";

    system(tempString.c_str());

}
aJ
Thanks. ErrMsg.toCString() gives the string.
No appropriate function found for call of 'oper 52]. Argument of type 'tentative class stringstream' could not be converted tempString <<"echo ";
hope you have included #include <sstream>
aJ
I did. Error still popping up. :(
I usually use ostringstream instead of stringstream. Maybe that will help with your error.Also, you need to convert the ostringstream instance to a std::string before you get the C string. Something along the lines of:system(tempString.str().c_str())
Dan