The task indicated that you can use a graphical interface. The task itself:

... Filling the stack: a) from the console. b) from file (file selection, current folder, any folder). ...

I have a console application (Win 7). Is it possible to somehow specify (write for example) the path to the file in the console that needs to be opened or is it just for the graphical interface? And if so, how?

  • Have you ever run a program with command line parameters? - VladD
  • Yes, I did. But here the choice in the program itself, when it is already running. - Jagailo
  • Ah, here you are talking about! Well, yes, you can enter for example the file name, what's the problem? cout >> "Enter filename: "; cin << filename; . - VladD
  • The task says select folder. Something like "enter the path" and write C: \ Users \ Name \ Desktop \ name.txt Is this possible to implement in general in the console? - Jagailo
  • one
    This is exactly what VladD said. - Nofate

1 answer 1

 #include <fstream> #include <string> #include <iostream> using namespace std; int main() { setlocale(LC_CTYPE, "Russian"); string filename; cout << "Введите имя файла: "; cin >> filename; ifstream fin(filename); if (!fin.is_open()) { cout << "\nФайл '" << filename << "' не может быть открыт!\n"; } else { for (string line; getline(fin, line);) { cout << line << endl; } } cout << endl; system("pause"); return 0; }