I will give an exact example of how this is done and why I want to do this.
The code look like this and I will read 5 lines from a .txt file that look like this:
1,1
1,2
1,3
1,4
1,5
The code to read these look like this:
Code:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main ()
{
std::vector<int> Number(5);
std::string Number1;
int d = 6; // Put d to its startvalue = 5;
int Number2 = 0;
int Number3 = 0;
ifstream File("File1.txt");
while ( getline(File, Number1, ',') )
{
d = (d - 1); // CountDown, First Value is (6-1) = 5
File >> Number2;
File.get();
Number[d] = Number2; // For the first line red in the file: Number[d] will have value 1
if (Number[d+1] == 1)
{
Number3 = 1;
}
}
return 0;
}
So what am I doing here ? While reading the file I am doing a countdown for int d = 6 so for the first line this will have the number: 5
As seen now below this I am giving Number[d] the value of Number2 wich is the first line in the textfile: 1
For the next line that is red in the file d wil have a value of 4 as it is a countdown so Number[d] will have the value of 2 this time.
This moment Number[d] will have the value of 2 and Number[d+1] will have the value of 1. yes.
Below this I am doing a ifstatement that says if (Number[d+1] == 1) { Number3 = 1};
This is True while reading the second line, yes.
So now you probably are asking why I want to find a way to write Number[1] instead of Number[d+1] as this works fine ?
There is a huge reason why. This is because I will write 100:s of pages of code that will exist of this example. This was a very easy example.
So writing Number[1] instead of Number[d+1] is easier and better for my purpose. So to find a way to do that would be nice how it could be done.
With pointers or other approches.
Hope this understands better what I am trying to do.