Read a .txt file and match it to a string

0

What I did in Linux to load the program to the console, only with a command in the terminal:

./s < EjemplosSudoku.txt

in windows is not possible, and I assume that you have to load it from the same code, calling the .txt file.

Could someone tell me how? And once loaded, how to take those characters and put them in a string?

  

Note:   It is a code of 200 lines, of solving sudokus, but it is only for this reason   say the solver, does not ask for data or anything like that. These   receive them from a .txt while it is in the format it should be.

    
asked by Shiro 04.06.2017 в 15:45
source

1 answer

3

The classic Windows console does not have input redirections, so

./s < EjemplosSudoku.txt

It will not work for you. You could try reading the route and the file from the program:

#include <fstream>
#include <iostream>
using namespace std;

int main (int argc, char** argv) {
    char data[100];
    ifstream archivo; 
    archivo.open(argv[1]); // Abris la ruta del archivo pasada por parametro

    cout << "Leyendo archivo" << endl; 
    archivo >> data; 

    archivo.close();
}

And you do it in the following way:

./s EjemplosSudoku.txt

This is valid for both Linux and Windows. I hope I have been helpful.

Greetings!

    
answered by 04.06.2017 в 17:45