File I/O

Hi, I have written the following code to add data to text files which are
required to store 3D scan data (I have to calculate the y-coordinate). My
code seems to work except that it stops working when I want to create more than
ten text files i.e. the directory I am trying to store them in will not hold any more than ten text files. Any ideas why this might be happening? Code is shown below. Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <string>  
#include <locale>
#include <iomanip>
#include <iostream> 
#include <fstream>  
#include <sstream>
using namespace std;
 
int main()
{
   // Declare required variables
   int prs, tpr, fs, j=0, k=0; 
   double inc;
   string file, file1, line,dir, s, s1; 

   // Prompt user for necessary scan information 
   cout << "Enter Feed Speed: ";  
   cin  >> fs; 
   cout << "Enter No. of Profiles/s: "; 
   cin >> prs;
   cout << "Enter Total No. of Profiles: "; 
   cin >> tpr;
   cout << "Provide name of directory: "; 
   cin >> dir;

   // Calculates increment in y-direction
   inc = fs / (float)prs; 
   // Initialise y coordinate to -ve increment
   double y = -inc; 

   for (int i = 0; i < tpr; i++) 
   { 
       // y co-ordinate increments
       y += inc; 
	   // increment file number (j) 
	   j += 1; 
	   // increment input file number (k)
	  
       
       // Converts coordinate to a string for insertion to *.txt file
       stringstream converty, convertj;
       converty << y; 
       convertj << j;
  
       // Creates output file stream object called "outFile" and prompts user to provide a name
       // Changes output filename with each successive increment of j

       s = convertj.str();
       char oname[] = "profile_00x.txt";
       oname[10] = s[0];
	   file = dir + "/" + oname;
   
	   double column1[] = {-37.43, -38.465, -33.23, -36.75, -37.45}; 
	   double column2[] = {150.26, 151.35, 152.86, 156.75, 153.83};
     
	   ofstream outFile (file.c_str(), ios::out); 
	   for (int k= 0; k < 5; k++)
	   { 
		outFile << column1[k] << "\t";
		outFile << converty.str() << "\t"; 
		outFile << column2[k] << endl;
	   }

       outFile.close(); 
	  
   }
 
 return 0; 
}
this:
1
2
3
4
s = convertj.str();
       char oname[] = "profile_00x.txt";
       oname[10] = s[0];
	   file = dir + "/" + oname;


Dont use char array, use strings and you'll see the problem more clearly.
Ah, now I see, thanks for that mutexe!
Topic archived. No new replies allowed.