• Steam recently changed the default privacy settings for all users. This may impact tracking. Ensure your profile has the correct settings by following the guide on our forums.

Problem with enums

ChurchedAtheist

Your resident psycho hobo
Im trying to create a program that converts unix/windows txt files. I think the issue is in my enums. any ideas?
[HIGHLIGHT=c++]enum FileType { WINDOWS, UNIX };
// Include Files //////////////////////////////////////////////////////////////
#include <iostream.h>
#include <iomanip.h>
#include <conio.h>
#include <fstream.h>

// Function Prototypes ////////////////////////////////////////////////////////

// Program Mainline ///////////////////////////////////////////////////////////

int main( )
{

char infile[256];
char outfile[256];
char ch;
ofstream output;
ifstream input;


cout << "Enter the name of the source file: ";
cin.getline( infile, sizeof( infile ) );
cout << endl;
ifstream fin( infile, ios::binary );
if ( !fin ) {
cerr << "File " << infile << " not found!" << endl;
cout << "Press any key to close the program" << endl;
getch();
return 2;
}//endif
cout << "Enter the name of the destination file: " << endl;
cin.getline( outfile, sizeof( outfile ) );
cout << endl;
input.open (infile, ios::binary);
output.open (outfile, ios::binary);
FileType = UNIX;
while ( fin.get( ch ) ) {
if ( ch == '\r' ) {
FileType = WINDOWS;
}else{

if ( ch == '\n' && FileType == UNIX ) {
output << '\r';
}//endif
output << ch;
}//endif
}//endwh
getch();
return 0;
}//endmn

[/HIGHLIGHT]
 

EvilSeph

Administrator
It would help if you could provide us with more information on what problem you're having... I think I'm not the only one who wants more details.
 

jparishy

New Member
You are using your enum incorrectly. You have an enum called 'FileType', but that's just it: 'FileType' is an enum, not an instance of the enum. You need to create an instance of the enum and use it as any other object, in this case I made an instance called 'myFileType.'

You could do:
Code:
enum FileType
{
    WINDOWS,
    UNIX,
};

int main(int argc, char** argv)
{
    [HIGHLIGHT]enum FileType myFileType;[/HIGHLIGHT]
    // ... stuff ...
    myFileType = WINDOWS; // Notice I manipulate 'myFileType' and not 'FileType.'
    // ... more stuff ...
}
 

Moca

New Member
It would help if you could provide us with more information on what problem you're having... I think I'm not the only one who wants more details.

You aren't the only person wanting clarification regarding the actual problem.

EndUnknown, it seems that you aren't actually familiar with using enums. You need to declare a variable of type FileType and use that in your code.

The following code
Code:
FileType = UNIX;
should instead be used like this
Code:
FileType type= UNIX;
and the rest of your code should use the variable "type".

In addition to that, you need to make a habit of closing any file that you open.
 

ChurchedAtheist

Your resident psycho hobo
EndUnknown, it seems that you aren't actually familiar with using enums.

no, im not really. I didn't understand what the instructor was saying when he discussed them.


{
[HIGHLIGHT]enum FileType myFileType;[/HIGHLIGHT]
Fixed it! thanks! :laugh: I initially had it set up the way you showed, but just missing that, and when i tried to fix it, i messed it up.

It would help if you could provide us with more information on what problem you're having... I think I'm not the only one who wants more details.

sorry. the problem was, the file would always write a carriage return and a line feed. looking at my code, i was 99% sure it was the enums.
 
Top