[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Boolean

Posted on 1998-08-04
7
Medium Priority
?
412 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

834 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