answersLogoWhite

0

How do you open a data file?

Updated: 8/17/2019
User Avatar

Wiki User

13y ago

Best Answer

You can use fstream header file to read and write in files. It has two main components ifstream: stream which you can use to read data, and ofstream which allows you to save in files. Use something like this:

#include

#include

using std::ifstream;

using std::cout;

using std::endl;

int main()

{

char fileName[] = "myfile.txt";//file to read from

ifstream inData;//stream to read from myfile.txt

int data = 0;//to read one number of type int (we assume that the file contains it)

inData.open(fileName);//connect the stream to the file

if (inData.fail())//if coult not open the file, program will be closed

{

cout << "Could not open the file" << endl;

exit(1);

}

inData >> data;//read one number from the file and save it in data of type int

cout << "File contains a number: " << data << endl;//show data on the screen

inData.close();//close the stream connected to the file

system("PAUSE");

return 0;

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you open a data file?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you open a file so that new data will be written to the end of the file's existing data?

append


What is a statement use to open data file in c?

FILE* file; file = fopen("some-file.dat");


How you can delete the data in the file by opening it in the C programming in read or write mode?

To delete all the existing data in a file, simply open it in write mode. If you open the file in append mode, you need to overwrite the existing data to delete part or all of that data.


How do you retrieve saved over data in notepad?

Just open notepad, go to file, open, and click on the file you saved it as


Which windows tool can you use to install the drivers needed so that a user can open a data file using an application that is normally not used with a file?

Data Sources Open Database Connectivity (ODBC)


Which windows tool can you use to install the drivers needed so that the user can open a data file using an application that is normally not used with the file?

Data Sources Open Database Connectivity (ODBC)


How you can delete the data in the file when you open the file in read or write mode in C programming?

When you open a file in write mode, eg. fp=fopen("filename.txt","w"); the content of the file is deleted.


Can you open a MS Works data file with open office?

Yes, it is possible to open a MS Works data file with Open Office. MS Works data files are generally stored with a &quot;.was&quot; extension, and they are documents produced by Microsoft Works, an office suite developed and distributed by Microsoft. While MS Works is no longer supported by Microprokey, the file format is still quite common and can be opened using software such as Open Office. Open Office is a free, open-source office suite that is developed and maintained by the Apache Software Foundation. It supports a variety of file formats, including MS Works data files. To open a MS Works data file with Open Office, simply launch the program, click on the &quot;File&quot; menu, select &quot;Open&quot;, and choose the file from its location. Open Office will then open the file and display it in its workspace.


What is the structures of the files and data bases?

I think file is a open structure. and the data base is closed structure.


What are the advantages of traditional file processing and database approach?

An alternative to using a database to store data is to use what are known as flat files. These are basically text files that are stored on your server that you can use to store your data, change, manipulate and generally use how you want. Although I'd recommend you use a database, you can use PHP's file processing system. There are 3 steps to writing data to a file: # Open the file (create if doesn't already exist) # Write data to the file # Close the file There are also 3 steps to reading data in a file: # Open the file (if cannot be opened, generate an errror) # Read the data # Close the file


Streaming Data?

Streaming Data is any type of data that can be read without having to open and close the input like a regular data file.


What is the term used to describe a file that data is read from?

It is known as an open file. Files can be opened for reading or writing, or both.