Te puede servir que utilices 
stringstream. 
Ejemplo:    
Código C++:
Ver original- #include <iostream> 
- #include <fstream> 
- #include <sstream> 
- using namespace std; 
-   
-   
- class MyClass{ 
- public: 
-     void someFunction(){ 
-         // code... 
-         // ouch! 
-         log << "my error string 1 in someFunction()" <<-  endl ;
 
-         // code... 
-         // ouch! 
-         log << "my error string 2 in someFunction()" <<-  endl ;
 
-     } 
-   
-     void anotherFunction(){ 
-         // code... 
-         // ouch! 
-         log << "my error string 1 in anotherFunction()" <<-  endl ;
 
-         // code... 
-     } 
-   
-     void saveErrors(const string& fname){ 
-         ofstream out(fname.c_str()); 
-     } 
- }; 
-   
- int main(){ 
-     MyClass mc; 
-     mc.someFunction(); 
-     mc.anotherFunction(); 
-     mc.saveErrors("myErrorLog.txt"); 
-     return 0; 
- }