I am trying to write data files out of a particle physics simulation that I have built, but I am having trouble trying to make the file name work like I want it to. The problem is the amount of data I have to write, and the number of files I have to write. I want to make a function that I can call, and have write the datafiles, but it needs to put the names for them together itself. Here is an example.
I understand the the += is not defined for the chars, but if i use strings i get other problems with opening the file. I could really use some help. Thanks
If the problem with strings is that the file opening function only takes c-strings, this is easily solved. You can just do myString.c_str() to return the c-string equivalent of your string, which will be accepted by the file opening function.
// necessary includes and stuff
int main()
{
string fileName = "myFile.txt";
fstream oFile;
oFile.open(fileName); //This gives an error in some compilers, as it will not impicitly convert string to c-string
oFile.open(fileName.c_str()); //This will work, as it explicitly does the necessary conversion
return 0;
}