Solved

Boolean

Posted on 1998-08-04
7
405 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 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…

809 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