Solved

Boolean

Posted on 1998-08-04
7
404 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now