i have a problem using WriteString ,i would like to concatenate a text with some variables
myfile.WriteString("file"+ p->file + "name" + p->name + "from" + p->dest + " size" + siz );
but i got this message error : Error 1 error C2110: '+' : cannot add two pointers

Re: Visual C++ Language error in concatenation


I suggest you use a CString object, and add the pieces using e.g. CString::Format. Another option is to use STL ostringstreams, such as

std:: ostringstream oss;
oss << "file" << p-> file << "name" ....

Re: Visual C++ Language error in concatenation


What the previous poster said!

Remember that in C++, a string literal ("Hello World!") is really just a pointer to an array of character data.

So when you try to concatenate strings using + , the compiler thinks you're trying to add two pointers together, and is understandably upset that you would attempt such a dastardly thing.

Some string classes overload the + operator for convenience:

CString strTemp = "Hello";

CString strData = strTemp + " World!";

But you'll end up with cleaner code if you take the previous poster's advice and use a formatting function:


string streams (ostrstream)

sprintf family of functions

Hope that helps.

Re: Visual C++ Language error in concatenation


thank you

but i have 02 things to ask.

i tried this

std:: ostringstream oss;

but i got this error Error 1 error C2079: 'strstrm' uses undefined 'strstrm' uses undefined class 'std::basic_ostringstream<_Elem,_Traits,_Alloc>'

2-how can i redirect the data to been writen if a file

Re: Visual C++ Language error in concatenation


Did you remember to add #include <sstream>

As for your second question, ostringstream isn't writing to file. The oss.str() would return a string (std:Tongue Tiedtring), and oss.str().c_str() will thus return a const char*. Depending on what WriteString takes as input, you could be able to pass the latter to it.