storing filenames in an array
Hello,
I want to create filenames such as Query.student.1.bin and save them in an array.
I have no problem when I don't include a "." between student and number "1" but as I add a "." there my code does not run. ( it does complie but crashes during the run)
string *filename_str;
filename_str =new string[Number_X_Axis];
for(i=0;i<Number_X_Axis;i++)
filename_str[i]="Query."+Table_Name+"."+convertInt(i)+".bin";
I would appreciate any of your comments on this.
Best
PA
Re: storing filenames in an array
Code:
string *filename_str;
filename_str =new string[Number_X_Axis];
Learn to use vectors.
Code:
#include <vector>
#include <string>
typedef std::vector<std::string> StringArray;
//...
StringArray filename_str(Number_X_Axis);
for(i=0;i<Number_X_Axis;i++)
filename_str[i]="Query."+Table_Name+"."+convertInt(i)+".bin";
In this day and age of C++, there is hardly a reason to use new[] / delete[] to create a dynamic array. Use container classes such as vector -- that is what vector is designed for.
Regards,
Paul McKenzie
Re: storing filenames in an array
Quote:
Originally Posted by
palireza
I have no problem when I don't include a "." between student and number "1" but as I add a "." there my code does not run. ( it does complie but crashes during the run)
You more than likely corrupted the memory due to incorrect usage of new / delete (which is why you should use containers, so these mistakes are not made).
In actuality, we don't know what you really did, since you didn't post your actual program that you're running. We don't know the data you're using, the flow of the program, where these lines are called/used, etc. We don't even know what "Table_Name", or convertInt() is.
Post a full, but simple program that demonstrates the error.
Regards,
Paul McKenzie