Sting Vector not storing correctly

My problem is with what should be a fairly basic procedure, but is causing a huge holdup in my program. I have a vector of strings which holds the names of files to open, these files are all named sequentiulay. The code reads as follows
1
2
3
4
5
6
7
8
9
10
11
  
void getname(){
     for (int i=0, j=i+1, k=j+102; i<102;)
     {
        string is= to_string(i);
        name1=is+"_500V_lm.dat";
         name2=is+"output.txt";
         names[j]=name1;
         names[k]=name2;
         i++;
     }

*Note* The variables are all global variables and I am using the name 1, name 2 strings as an attempted fix for the problem

So the problem is that when I try to access the names stored in the names vector, it returns empty, but name1&2, when checked using cout, are fine.

also, before running this sub process, as a way to try to diagnose this problem I checked the vector using

1
2
names[1]="name";
	cout << "just to check..." <<names[1]<<endl;

and it returned fine...

Is it a code error or compiler strangeness?

EDIT*: The program runs fine, it returns zero and goes through the entire program, but it does not create the output files
Last edited on
iirc you've got a `names' vector that holds first the input filenames, and then the output filenames.
¿is the vector big enough? (using `names[k]' would not resize the vector)
¿why does the vector index start in 1?
You initialize `j' and `k' but never modify them, they value 1 and 103 for the entire loop execution.

> So the problem is that when I try to access the names stored in the names vector, it returns empty
show how you are doing that.

> but it does not create the output files
¿with what name you are trying to create them?
¿are you sure that you are checking the correct directory?
¿do you have writting permissions in that directory?
¿did you use the "create if does not exist" flag?
The vector is large enough, adding j++ and k++ after i++ now makes the program crash.

Which was an off by one error.

Resolved
Topic archived. No new replies allowed.