Meaning of ./main command in terminal [duplicate] - c++

This question already has answers here:
Why do you need ./ (dot-slash) before executable or script name to run it in bash?
(9 answers)
Closed 7 years ago.
I am working with this c++ project for making command line text editor like Vim. The documentation tells that in order to run this text editor in terminal you need to write command ./main in the project folder.
The project folder has main.cpp file. Is this a command to execute that file (may be I am wrong) or this command is a standard terminal command.
Thank you.

Running ./main means run main from the current directory (.).
The current directory is normally missing from $PATH so you have to specify it explicitly.

Related

'cd ..' is not working in system("") in c++ code running in ubantu environment [duplicate]

This question already has answers here:
changing the directory from inside a c program under windows using system command
(5 answers)
Closed 9 months ago.
Currently I am in test directory and I am trying to change directory from test to src and run another .so file
below is the code
system("cd ..");
system("cd src");
system("./shapessenderros2");
folder structure is
test and src folders are in same directory
Each system call creates a new sub shell and whatever you do to the envionment of such a shell will not affect any other sibling shells. Each process inherits the environment from the parent process. You could get around the problem by running all the commands in the same shell:
system("cd ../src;./shapessenderros2");
or, only execute the command if cd succeeds:
system("cd ../src && ./shapessenderros2");
Or set the correct directory before calling system:
#include <cstdlib>
#include <filesystem>
// ...
auto owd = std::filesystem::current_path(); // save the current directory
std::filesystem::current_path("../src"); // change directory
std::system("./shapessenderros2"); // run the command
std::filesystem::current_path(owd); // set the directory back

Output file where executable is located C++ [duplicate]

This question already has answers here:
Get path of executable
(25 answers)
How do I get the directory that a program is running from?
(26 answers)
Finding current executable's path without /proc/self/exe
(14 answers)
Closed 2 years ago.
Is there a way to set the output directory of a file in the same one where the executable is located and not where the executable is executed?
ofstream outputFile;
outputFile.open("text.txt");
outputFile<<"test";
When I click on the .exe it typically outputs the file in the same directory I started it but when I execute it in different ways say for example with a .BAT file, the output directory is automatically set where I started the .BAT file (not where the .exe is located)

How do I run cpp program directly from Vim? [duplicate]

This question already has an answer here:
How to compile a cpp file directly from vim editor in Windows?
(1 answer)
Closed 2 years ago.
I've recently installed Vim on my Windows 10 and also the g++ compiler through mingw.
I want to directly compile and run my cpp program from Vim.
I've tried the following command.
:!g++ hello.cpp -o hello
below is the image for the reference
https://imgur.com/iYe0aVv
Probable answer to your problem: give the full paths: % for the source and %< for the executable.
Also, please, copy the message, avoid screenshots.
And finally, you should have a look at this question from this morning... IOW, prefer using quickfix feature. How to compile a cpp file directly from vim editor in Windows?
Regarding the execution on the current (monofile) program, it's
:!./%<
" or
:term ./%<
(you may have to add .exe after %<. IIRC, this is not necessary)

How can I run an executable and take input from a text file on Linux? [duplicate]

This question already exists:
Command line parameters c++ [duplicate]
Closed 3 years ago.
How can I run an executable and take input from a text file on Linux?
I was trying to use:
./(name of my executable) TextFile.txt but it does not work.
you can do ./(name of exe) < input.txt
and if you want to write the output to a text file you can do:
./(name of exe) > output.txt

how to remove directory in linux which is not empty [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to remove a non-empty directory in C++?
I have the directory name. i am trying remove(dir_name), but as the directory is not empty its returning false.
How can i delete the directory. Is there any built-in function which i can call??
To recursively remove a directory and all it's contents, use the following command in a terminal:
rm -rf /path/to/dir
Edit: Seems I was confused by your mention of built-in function, I was assuming a function "built into" linux. Obviously this is not C++ code. If that's what you want, see the question linked to in Fred Larson's comment to your original question.