Solved

Boolean

Posted on 1998-08-04
7
403 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

758 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

22 Experts available now in Live!

Get 1:1 Help Now