[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

easy wright to file question

Posted on 1999-01-08
1
Medium Priority
?
231 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
ID: 1181788
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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.
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.
Suggested Courses

830 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