Solved

easy wright to file question

Posted on 1999-01-08
1
215 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Getting IP address 8 104
Find Visual Studio Tools 2 126
fatal error: vector: No such file or directory   Visual Studio 2015 for Arduino 4 106
why doesn't assert terminate here? 2 11
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 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.

730 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