I want to read and write csv files using C++.
The constraint is that I have to write the path in the console.
For example, if I want to read a file, I have to write in the console :
Read "filePath"
And if I want to write a file :
Write "filePath" "delimiter"
I have made functions that work, but without indicating the path in the console.
Here is my main function :
int main()
{
SudokuGrid sudokuGrid;
bool done = false;
string command;
while (!done) {
cout << "Enter a command :" << endl;
cin >> command;
if (command == "Read") {
sudokuGrid.readGridFromCSVFile("Sudoku.csv");
cout << endl << "Grid read with success !" << endl << endl;
}
else if (command == "Write") {
sudokuGrid.writeCSVFileFromGrid("Sudoku3.csv", *";");
cout << endl << "The file has been created !" << endl << endl;
}
else if (command == "Display") {
cout << "Here is the grid !" << endl << endl;
sudokuGrid.printGrid();
}
else if (command == "Exit") {
done = true;
}
else if (command == "Help") {
cout << "TODO" << endl;
}
else {
cout << "Incorrect Command" << endl << endl;
}
}
return 0;
It works but my problem is that I write the file path directly in the main function, but I want to be able to write it in the console.
I have tried :
cin >> command >> csvFilePath;
if (command == "Read") {
sudokuGrid.readGridFromCSVFile(csvFilePath);
cout << endl << "Grid read with success !" << endl << endl;
sudokuGrid.printGrid();
}
It works but only with two inputs (the command "Read" and the file path) but I also want to be able to do it with one input (Display) or three inputs (Write, file path and delimiter)