hello,

i am a little confused with something. im reading values from a text file which only contains 1's and 0's. here is the code.

char y;
ifstream inFile2;    
inFile2.open("c:\\binary.txt");

ofstream fileout2;
  
   while (inFile2 >> y) 
   {
       
       //cout<<y<<"  ";                this would print either a 1 or 0                                              //    based on file.
        if (y=1)  //here lies the problem
        {
            
            fileout2.open("c:\\confidential.lck");     
       
        


        }
        
        else 
        
        
        std::remove("c:\\confidential.lck");
        
        Sleep(1000);
        }
        
       
     inFile2.close();

i want to compare the value of y. if it is a one, it should create the file and if it is a 0, delete a file.

i also tried y==1 and y=="1" but it does not work.

any help will be appreciated.
thanks.

single characters take ' and ', not " and ". if( y == '1' )

thanks mate! silly me!

Oh god I've just read for about half an hour on string manipulation when ' and ' was what was missing... :|

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.