mardi 7 septembre 2021

C++ how to get output into a file

So I am not sure how to get the output to like a .txt file, the code keeps giving me a .txt file but it is always empty. I know I am supposed to include a line where it outputs the information but I am uncertain of what to put in the line since its a void function and it doesn't return anything, would changing it to a different type of function solve the problem?

Code:

#include <iostream>
#include <string>
#include <fstream>
#include "ArgumentManager.h"

using namespace std;

void permute(string a, int l, int r)
{
  if (l == r)
    cout<<a<<endl;
  else
  {
    for (int i = l; i <= r; i++)
    {
      swap(a[l], a[i]);
      permute(a, l+1, r);
      swap(a[l], a[i]);
    }
  }
}

int main(int argc, char* argv[])
{
  ArgumentManager am(argc, argv);
  ifstream input;
  ofstream output;

  string infileName = am.get("input");
  string outfileName = am.get("output");
  input.open(infileName);
  output.open(outfileName);

  string str;

  int n = str.size();
  permute(str, 0, n-1);

  return 0;
}

Aucun commentaire:

Enregistrer un commentaire