Here we go again... Correctly indenting code:
Originally Posted by
Coding
Code:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
int main ()
{
std::string Date;
int Time = 0;
//
int HigherTim = 0;
ofstream Test;
Test.open ("file2.txt");
ifstream myfile ("file1.txt");
ifstream file0 ("file0.txt");
getline(myfile, Date, ','); // 12/04/2007
myfile >> Time; // 2111
while ((! myfile.eof()) & (Date == "12/04/2007") & (Time > Time))
{
HigherTim = Time;
}
if (HigherTim > 2111)
{
Test << "Test " << HigherTim <<"\n";
}
return 0;
}
Also note that & will not do what you think it will. It's a binary OR operator, not the AND operator. That's &&. Two & after each other.
And I generally do not recommend such complex loop conditions, because it's hard to read and easy to make mistakes.
Instead, what I do, is make an infinite for loop and check conditions in the loop manually and then break if if true. And using eof() as a loop condition is generally bad; you should read the FAQ about that:
Code:
for(;;)
{
if (condition) break;
}