vijay wrote
>
can be done as below.
#include <iostream.h>
#include <stdlib.h>
#include<string.h>
void main()
{
char *st = new char[20] ;
char s[3] ;
for(int i = 0 ; i<10 ; i++)
{
strcpy(st,"result") ;
strcat(st,itoa(i,s,10)) ;
strcat(st,".txt") ;
cout<<" File name = "<<st<<endl;
}
}
When you folloe up to Jim Langstons post, then I assume you think
this is a better way. I would disagree.
There is why:
1)
How many places do you have to change or check your code if I don't
want 10 but 100 filenames?
Jim: 1
vijay: 5! ( are they arrays big enough?)
if I want a diferent beginning of my filename..
Jim: 1
vijay: 3!
2)
You dont include the correct c++ headers. Some of your headers are
not needed by your code, nor should they have the ".h" endings!
3)
Using arrays is evil! To many things can go wrong with arrays, and
c++
offers a safer alternative namely std::string. That class was built
to avoid having to deals with strings. Its a standard class so
everbody reading the code knows what it does ( it handles stings),
and they know it is safe (it will handle any reasonable string given
to it)
4)
You give the wrong return type to main(). main() returns int. it
always has, and no compiler should accept this.
5)
You did not compile your code, did you... It would have caught a few
typos, and missing qualifications. cout should be std::cout, endl
should be std::endl
If you maded it this far, I will admit, that your solution would
probably very close to what I would do in C.
Bo Møller
--
Bo Møller
Hobby-Programmer