Given your comments, I believe that you're looking for std::ofstream
in your first program and std::ifstream
in your second program. If program A is your first program with a very large code base and program B is your second program which will want to display the data from program A, then program A would use std::ofstream
and program B would use std::ifstream
.
If you follow the links, you'll find the description of what they do and at the bottom of the page, there's a code example. Don't start with program A that takes 7-8 hours to compute. You'll have to make sure that the output is correct before you can even use the data for input and any mistake on the way means that you'll have to restart. If you want to test and manually verify your data you can skip the second parameter as such, std::ofstream ostrm(filename)
but then you need to rework how you operate the stream. Depending on your data, this will be the critical part of the operation.
// Code example from cppreference - ofstream
#include <iostream>
#include <fstream>
#include <string>
int main() {
std::string filename = "Test.b";
{
// This will create a file, Test.b, and open an output stream to it.
std::ofstream ostrm(filename, std::ios::binary);
// Depending on your data, this is where you'll modify the code
double d = 3.14;
ostrm.write(reinterpret_cast<char*>(&d), sizeof d); // binary output
ostrm << 123 << "abc" << '\n'; // text output
}
// Input stream which will read back the data written to Test.b
std::ifstream istrm(filename, std::ios::binary);
double d;
istrm.read(reinterpret_cast<char*>(&d), sizeof d);
int n;
std::string s;
istrm >> n >> s;
std::cout << " read back: " << d << " " << n << " " << s << '\n';
}
With your data correctly outputted to a file you'll be able to read from it by creating the std::ifstream
. Make sure to verify that the stream is open:
std::ifstream istrm(filename, std::ios::binary);
if(istrm.is_open())
{
//Process data
}