I wonder for a solution/approach how to use combinations for a value in a function and to put this results into different files. I will try to put out all information of what I am doing and what I want to do and then explain again.
I am reading a .txtfile from top to bottom. (The .txtfile look as follows, 2 lines)
09/19/2006,2113,21.00
09/19/2006,2114,22.00
The line represent: Date,Time,Open.
(The code I use to scan this file look as follows)
Code:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
int main ()
{
std::string Date;
int Time = 0;
char Comma;
double Open = 0;
ofstream Test;
Test.open ("file2.txt");
ifstream myfile ("CCE.txt");
while (getline(myfile, Date, ','))
{
myfile >> Time; // 2113, 2114
myfile >> Comma;
myfile >> Open; // 21, 22
myfile.get(); // read in trailing newline character
if ((Time >= 2113) && (Open >= 21))
{
Test << Time <<"\n";
}
} // End of While Statement
return 0;
} // int main braces
Now I will explain exactly what I want to do.
I have a function in the code that says:
if ((Time >= 2113) && (Open >= 21))
For the first line in the file this statement is true and will return: 2113 to a file called "file2". This is quite simple.
So what I want to do now is this. I will give an example.
So I have 2 values called, Time and Open, okay!.
For these values that for the moment in the function is: 2113 and 21.
I want the function to test different combinations for these, that I will have an oppurtunity to specify with an interval like this:
For Time:
2113 To 2114 Interval: 1 (This meens to first test 2113 and then 2114 because the interval was set to 1)
For Open:
21 To 22 Interval: 1 (This meens to first test 21and then 2 because the interval was set to 1).
(It is like a "StartValue" To "EndValue" with an Interval, ex: 1 in this case)
So the combinations out of this that will tests is Totally 4 then, that look like this:
2113 21
2114 22
(2113 and 21, 2113 and 22, 2114 and 21, 2114 and 22)
This makes as seen 4 combinations, that will be tested for each row in the file. So for the moment as seen in my code posted I can only do 1 combination.
What I then want to do is to store the output to 4 different files(Each combination will find it´s own file. For example will the first combination store its values to a file called: file1, Combination 2 will store its values to a file called: file2 etc... to file4 for the last combination.
Is there any ideas how I can solve this. I will be very happy for ideas and help on this.
/Coding.