Solved

Boolean

Posted on 1998-08-04
7
406 Views
Last Modified: 2010-04-02
I am writing a boolean variable to a file and I later need to read it into a boolean variable.  I first tried writing "TRUE" or "FALSE" to a file and read it into a boolean variable, but I did not have any luck.  I am now writing a "1" for true or a "2" for false to the file.  I read this into the boolean variable, but it doesn't seem to working either.

So, I am trying to use the CBool function that I have found, but have been unsuccessful.  Does anyone know how to use it or have another idea.  Some example code is desired.
0
Comment
Question by:stchsc
7 Comments
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1169417
Boolean variables in c++ represented as 1 for TRUE and 0 for FALSE. You can write the variable itself into a file, you don't have to use any symbols:

BOOL b=TRUE;
CFile fl("C:\\1.dat", CFile::modeWrite | CFile::modeCreate);
fl.Write(b, sizeof(BOOL))
fl.Close()
0
 

Author Comment

by:stchsc
ID: 1169418
I am having trouble reading a "TRUE" or "FALSE" or "1" or "2" into a boolean variable from a file??  What to do?  I tried the code above without success.
0
 
LVL 4

Expert Comment

by:agreen
ID: 1169419
Please post a piece of code that opens file and writes the variable.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:stchsc
ID: 1169420
Thank you very much for the help.  However, I have solved the problem.  Thanks again.
0
 
LVL 4

Accepted Solution

by:
sganta earned 50 total points
ID: 1169421
Try this

enum  boolean = {FALSE,TRUE};

void main(void)
{
  boolean x,y,z;
  x = TRUE;
  y = FALSE;
.......
}
0
 
LVL 4

Expert Comment

by:sganta
ID: 1169422
There is small mistake

Pl. correct this as


    enum  boolean {FALSE,TRUE};

    void main(void)
    {
      boolean x,y,z;
      x = TRUE;
      y = FALSE;
    .......
    }
0
 

Author Comment

by:stchsc
ID: 1169423
Thanks for the help, but I have already figured it out.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question