?
Solved

easy wright to file question

Posted on 1999-01-08
1
Medium Priority
?
224 Views
Last Modified: 2010-04-02
How do I wright a variable to a file?
0
Comment
Question by:bradsoblesky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
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 clear a vector as well as how to detect empty vectors in C++.
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

771 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