Solved

easy wright to file question

Posted on 1999-01-08
1
181 Views
Last Modified: 2010-04-02
How do I wright a variable to a file?
0
Comment
Question by:bradsoblesky
1 Comment
 

Accepted Solution

by:
alexoss earned 0 total points
Comment Utility
That depends on how you want the variable to be used in that file, and on the type of variable you want to write.  Generally, variables are stored in a "binary" format or in a "text" format in a file.  Text format files are more common because more applications tend to be able to read them.

In C++, the easiest way to write a variable to a file in text format is to use the iostream insertion operators, like this:

#include <iostream>

int main()
{
  double c = 5.0;
  fstream outfile("myfile.txt");
  outfile << c << endl;
  return(0);
}
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 learn how to clear a vector as well as how to detect empty vectors in C++.

763 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

11 Experts available now in Live!

Get 1:1 Help Now