How to create a data file?

I will be designing a program where the user enters the name of a data file. The file will contain data for the engine of a rocket.

How do I create this data file?
Hi, the problem does not seem very clear to me... Do you want to know how to read / write on a file with a C++ programme? If this is the case, I can point you to this page: http://www.cplusplus.com/doc/tutorial/files/. Otherwise, please be more specific about what you want.
you can create the file with an instance of std::ofstream
you can also create a file when right-clicking in an explorer and then "new - file".

As you see, this list might get quite big so pleace be more specific ;)
Well in one of my in class assignments we design a program where we entered the name of a txt file. The program reads the txt file and outputs the data in the file. This txt file was created by my teacher and stored in a folder for all students to access. This is how I want to create a txt file....How do i do this??

This is how I want to create a txt file....How do i do this??

Didn't your teacher allready create the file and you want to read it?
you can use the fstream library for both of them.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <fstream> // std::ifstream, std::ofstream
#include <string> // std::string
#include <algorithm> // std::copy
#include <iostream> // std::cout

int main()
{
// get filename
    std::string file_name;
    std::cout << "What name should the File have?" << std::endl;
    std::cin >> file_name;

// create file
    std::ofstream ofile(file_name);
    // write stuff
    ofile<< "stuff" << std::endl;
    ofile.close() 

// read file
    std::ifstream ifile(file_name);
    // read file and print data on console
     copy(istreambuf_iterator<char>(ifile),
              istreambuf_iterator<char>(),
              ostreambuf_iterator<char>(std::cout));
    ifile.close();
}
Last edited on
Topic archived. No new replies allowed.