I use more and more qt as a regular IDE. I write for example this piece of code:

std::ofstream out("myfile.txt",std::ios_base::out); out<<"HelloWorld<<"; out.close(); 

The file does not create. If you put in the project directory for example myfile2.txt and write std::ifstream file("myfile2.txt",std::ios_base::in); he will not open it. The project was created as: A project without using Qt -> A simple project in C ++. Linux OS

  • Are you sure you are not creating? Maybe it creates, but not where you are looking? Specify the full path to the file. - VladD
  • @VladD tried to do a full search, just prescribe full paths, whether they are correct or not I can’t say because there is no library <dir.h> - ParanoidPanda
  • Well, try to create the file "/tmp/myfile.txt" , there it is impossible to make a mistake. - VladD
  • one
    Either you specify the full path, then the file is searched for where you specified (or put there). Or do not specify, then the file is in the current directory (or put there). What is the current directory, each system has its own idea :) - VladD
  • one
    Usually when you start a program, the current directory is the one from which you run the program. For example, if you run the /tmp/a/prog program from the /tmp/a/prog , then the current directory is /tmp . This is not necessarily the directory in which the program resides, and certainly not necessarily the directory in which the source codes lie. - VladD

1 answer 1

File does not create

he won't open it

The file is necessarily created (if the program has enough rights). Search is also made.

But in the directory of the resulting executable file. That is, the relative paths you write to similar (used by a ready-made, working program) files are counted, starting primarily from the root directory of the program being created. You can see its address by going to Qt Creator in the following way:

Qt Creator > Проекты > Запуск (required "start", please note)> Программа

Screenshot of the desired field