Originally Posted by
whiteflags
Well actually, I would fix this first:
Error 1 error C2371: 'c_file' : redefinition; different basic types in line 164
In the code snippet you showed, c_file was defined as an ifstream on line 8 and an ofstream on line 19, in the same scope (i.e. statement block). You can't do that, so it's an error.
I changed it like this:
Code:
// displays 1st, 2nd, 3rd, and 4th highest frequencies
cout << indexoffirst << " = "<< first << endl << endl;
cout << indexofsecond << " = " << second<< endl << endl;
cout << indexofthird << " = " << third << endl << endl;
cout << indexoffourth << " = " << fourth << endl <<endl;
ifstream c_file ( "D:\\LotteryPrograms\\Fla_Mega_Money\\Highest_Frequencies.txt" );
if (!c_file )
{
cout << "Can't open input file" << " Highest_Frequencies.txt " << endl << endl;
cin.get();
exit(1);
}
ofstream d_file ( "D:\\LotteryPrograms\\Fla_Mega_Money\\Highest_Frequencies.txt" );
if (! d_file )
{
cout << "Can't open input file " << endl << endl;
cin.get();
exit(1);
}
c_file >> indexoffirst >> " = " >> first;
c_file >> indexofsecond >> " = " >> second;
c_file >> indexofthird >> " = " >> third;
c_file >> indexoffourth >> " = " >> fourth;
But I still get the error:
Code:
Error 1 error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::basic_istream<_Elem,_Traits>' (or there is no acceptable conversion) line 174, 175, 176, 177
I still don't understand. I thought that ifstream treated as cout and ofstream treated as cin files.
I am trying to write
Code:
cout << indexoffirst << " = "<< first << endl << endl;
cout << indexofsecond << " = " << second<< endl << endl;
cout << indexofthird << " = " << third << endl << endl;
cout << indexoffourth << " = " << fourth << endl <<endl;
which is now just written on the screen into a file.
If I change
Code:
c_file >> indexoffirst >> " = " >> first;
c_file >> indexofsecond >> " = " >> second;
c_file >> indexofthird >> " = " >> third;
c_file >> indexoffourth >> " = " >> fourth;
into
Code:
d_file >> indexoffirst >> " = " >> first;
d_file >> indexofsecond >> " = " >> second;
d_file >> indexofthird >> " = " >> third;
d_file >> indexoffourth >> " = " >> fourth;
I get more errors than I can count!
Can you please explain what is wrong? . . . . therry