I try to debug by using cerr in c++. I know it's efficient for text editors like sublime.
But I wanted to know if there is a way i can open the output error text file on codeblocks in real time which would reflect the changes as soon as I run the program.
Right now when i do this, this happens:
Is there any way to do this efficiently,so that the file gets updated withput giving prompt each time?
Related
I am new to C++ and I am using the free version of Microsoft Visual Studio 2019.
I have written a small code which I use to integrate some differential equations (by using odeint libraries provided by Boost).
After the integration process ends, the time evolutions of the state variables are stored in the matrix mat (I use the Eigen libraries to define it row by row):
MatrixXd mat(t,4);
for (int i = 0; i <= t-1; i++)
{
mat.row(i) << times[i], x_vec[i][0], x_vec[i][1], x_vec[i][2] ;
};
Then I save the content of the matrix in a .txt file:
ofstream file("mat_save.txt");
if (file.is_open())
{ file << mat << '\n'; }
file.close();
However the .txt file is created only if I run the code in Debug mode, while if I only compile it the file is no longer created and no output can be displayed in the Console, since it is only opened when Debug mode is chosen.
Is there a way to make the Console appear and remain open and also to make the .txt file to be successfully saved, simply "compiling" the code avoiding debugging?
If so, I would save lot of time because the debugging is quite slow.
Thanks in advance!!
I'm not sure if by debug you mean running the code in Visual Studio vs compiling and then running the created exe. It Kind of sounds like a relative path issue.
Try using a full path. Or try opening a command prompt, cding to the path with the exe and then running it and check to see if the file is created in the folder you cded to.
You can also try opening the exe in Visual Studio like it was a project. Another thing to try is attaching VS to a running process to debug: http://msdn.microsoft.com/en-us/library/c6wf8e4z.aspx
The Windows Powertool "Handle" can display what handles a process is currently using which could be useful in determining if it is writing a file somewhere unexpected: https://learn.microsoft.com/en-us/sysinternals/downloads/handle
I am running codeblocks on Linux Mint 17 and I have not had any issues until now. I am running a relatively long sequence of output and my terminal will only show the last 500 lines of output to Console (terminal). I am needing to view the beginnining portion of the sequence and I would like to know if there are any settings I could change within my OS or codeblocks itself to adjust the amount of output that is printed to console. Perhaps there is a way to save the console output to file (without coding for filestream)? Thank you! I appreciate your help greatly!
EDIT:
I forgot to mention I am using C++ and the console I am using is Linux Mint default terminal.
If you are using the terminal you could just ouput it to a text file like this:
./execution_file > text_file.out
The executable file should be in the same folder as the cpp file, but if you cant find it you could use:
g++ -o codefile.cpp executionfile
You can use less command in linux.
Ex : ./a.out (executable file) | less
In windows you have "more" command.
as like above linux command, you can pipe your output to "more" command and see full result.
Is there any way that I can see the run time of my C++ program in Geany? I am trying to add a execute command like this "time(./%e<i.txt)" it is giving error
./geany_run_script.sh: 5: ./geany_run_script.sh: time(./g<i.txt): not found
I have i.txt in the same directory as output file.I just want to know the runtime of my C++ programs while taking input from .txt file without writing the commands every time in the terminal myself any way I can do this?
I really like Sublime Text 2 for HTML/CSS and Python and I'm starting to learn C++ and I want to use Sublime Text 2. I have looked at a few tutorials on installing g++ in order to run C++ in Sublime Text 2.
This is my code:
// my first program in C++
#include <iostream>
int main()
{
std::cout << "Hello World!";
}
And when I run it it says [Finished in 1.5s] but nothing got printed. I have added the environment variables path but nothing gets printed.
The problem is that you are pressing build, which compiles your source code into an executable but does not run it. The [Finished in ...s] you are seeing is how long the program took to compile.
What you need to do is build like you currently are, but then go to the directory where your source code is and run the executable file that's in there*. There is a run option within the editor, but it doesn't always work on Windows**.
*if the program closes instantly, try running it from the console or adding std::cin.get() to the end of your program
**often due to incorrect configuration
Can i go to the line of error , while compiling a C or C++ project ? Usually by executing make , and parse the error string , and go to the specific file , and the line with errors.
Is there already an usable plugin ?
Yeah this is already buit into vim. After typing :make type :cwindow to bring up the error list. You can then navigate to the errors using this window.
You can as well after :mak or :make do :cope to open the window with compiler output and once you are done :clo to close it.
Use :cn and :cp for jumping to next and previous error or when you are in the window go to line that has the error with file name, line & column and press enter to jump there.
IIRC, this functionality is built into vim. A quick google search revealed this useful link. This describes vim's features for navigating the errors after a make.