I am trying to create n number of files (n being an integer), by passing the name through a character array (and obviously changing its value at each iteration). But the problem is that the program compiles and executes but not a single file is created.
Here is my code snippet.
void file_phipsi(int m)
{
int a=0,n=0;
char *str1;
while (m!=0)
{
n=str[a].length();
str1=new char[n+6];
strcpy(str1,str[a].c_str());
strcat(str1,".txt");
cout<<str1;
fstream f(str1,ios::out);
a=a+3;
m--;
f.close();
}
}
Files are created for me. Do you look in the program working folder?
Unrelated: why are you increasing a by 3? What is the content of str array? Do you use C++11 because your program way more complex than it should and additionally you ahve a memory leak here.