I think you should firstly understand how a C-string works... a C-String is always an array of chars... but an array of char is not always a C-String.
The "definition" (not a formal definition, but something close to it) is that a C-String contains a sequence of bytes that will represent a string (characters) and the end of the string will be marked with a null-byte (0)
This is a C-String:
char myString[4] = { 'a', 'b', 'c', 0 };
This is NOT a C-String:
char myBuffer[3] = { 'a', 'b', 'c' };
Checking your example... trying to make "matrix"+a+b+".txt"
shows that you are actually looking for construct a C-String with different types.
--
So, in order to mix different types of data in order to build a string we have several options...
- In C: use
snprintf()
- In C++: use
std:string
or std::ostringstream
There are more options for both, but these above are very common.
The std::string
in C++ is NOT a C-String... but can be converted to one with the function .c_str()
.