Limited .exe Output in C++ [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I'm sure this is a simple question, but I tried a couple google searches and wasn't sure what keywords to search.
After executing my program in C++ the .exe window that opens is only showing the bottom part of my output, while cutting off the top. Any thoughts on how to view all of my output?
Thank you.

You can redirect the output of the program to a file:
your-program.exe > file.txt
Alternatively, you can pipe the output into more:
your-program.exe | more
This will pause the output of your program when it fills one screen until you press the space bar.
Both approaches have their pros and cons: if you redirect the output to file and open that file while the program is running, you might not see the last chunk of data, because the OS might buffer the data before writing it to hard disk.
If you pipe the output into more then the execution of your program might be suspended while more is waiting for your input.
[Edit: incorporated enhzflep's suggestion of using a redirection to a file.]

suppose you have an "a.exe" program
execute the program like this:
a.exe >1.txt
and open the file "1.txt" with notepad or other editor(such as notepad++).

Related

Is there a way to have a C or C++ program open a new terminal window and start executing code for you? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 months ago.
Improve this question
I want to create a C or C++ program that automates some things for me.
The idea is as such: I run the program ./a.out and sit back and watch as it opens up three or four new terminal windows and runs various UNIX commands. Is there a way to do this?
I am on a MacBook.
As the comments point out, this is probably best accomplished by a shell script. However, you can execute shell commands from C with the system(3) standard library function. To open a terminal, just run a terminal with a particular command. For example:
system("xterm -e 'echo hello; sleep 5'");

How to run gcc compiler from my qt application? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
1- I am working on a project and i have made a simple GUI but i want to make a run button in my GUI to compile and run c code ??
(i want to make simple ide so i used qt to make my ui but i can not make a button which send arg to windows terminal )
2- How to have a good start with Qt (need a good tutorial)
You can run any program from Qt5 and capture it's standard output using the QProcess class. The official documentation with examples is here: http://doc.qt.io/qt-5/qprocess.html
So what I would do then is simply make a GUI with 2 QTextEdit widgets, one for the code and one for the compile/run output. Documentation for QTextEdit is here: http://doc.qt.io/qt-5/qtextedit.html
So the "compile and run" button would simply
Take content of upper QTextEdit into a temporary text file on disk. Documentation for QFile is here: http://doc.qt.io/qt-5/qfile.html
Start gcc to complie the file using QProcess and capture the output in a string
Replace the content of the bottom QTextEdit with the output of the compilation.
Look at return code from QProcess to see if compilation was successful.
For successful build, simply invoke QProcess again, this time for the executable that was built by gcc to run the code, while appending any output to the bottom QTextEdit.
NOTE: As an exercise this is probably going to be fun and provide ample opportunity for learning, however I doubt this would be very useful on its own.
Good luck!

Why my DOS interface will flash across when I run a cpp file in Sublime Text 3? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Just as you see in the title? I have been confused about that for a long while.
In many windowing systems, a console window is opened up when your program starts executing. When your program stops executing the window disappears. This regardless to any output sent to the console.
If your program is quick, the console will "flash" by.
If you want your console window to stay for a while, you will need to pause execution. My idiom is:
std::cout << "\nPaused. Press Enter to continue.\n";
std::cin.ignore(10000, '\n');
I don't use system("Pause") because not all operating systems have a Pause command.

Linux C/C++ keyboard ctrl+[somekey] and ctrl+alt+[somekey} [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have been thinking how to listen keys and key combinations in Linux (and C/C++). My program structure is following:
Get text input. If ctrl + [somekey] is pressed, print text from a file called somekey.txt.
For example if you press ctrl + a the program should print the text from a file called a.txt.
If ctrl + alt + [somekey] pressed: the program saves already given (not pressed enter) text input to a file called somekey.txt. Example: ctrl+alt+a --> before typed text to file called a.txt. It should also replace the old text in the file if excist. It can be done by force-creating the file.
I have no idea which library I should use. Maybe sdl or ncurses? The program can also be written in some other languague as long as the program stays lightweight to run in Computers like Raspberry Pi. Could someone write me a little code which follows this structure? Thanks in (code) advice!
If you go down the SDL route, it should be pretty simple. In general, your program will have a flow like this:
Initialize SDL
Event loop
Wait for event
Handle event, possibly exiting loop
Shut down SDL
In that “handle events” step, you'll probably want to check to see if the event is a keyboard event, and if it is, switch on what modifier keys are held down. Then you can perform whatever logic is necessary.
See the documentation, and in particular the keyboard category for more information.

How to continue program after another window is opened [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
So I am an amateur programmer, currently enrolled in my second semester of C++ (yesterday we learned about structs just to give you an idea of what I know...).
I am creating a simple program to help me file documents at my internship.
I am using a system command(yes I know its dangerous and a big security risk), to open a pdf in firefox so that I can see the file and know where to put it.
I have successfully opened firefox and opened the pdf.
However my program stops running until I close firefox.
My question is how do I continue my program at the same time?
Is there an easier way to display a pdf in an executable?
edit:
Here is the function I use to open the firefox window with the pdf in it:
void openPDFBrowser (char array[])
{
ofstream outFile;
outFile.close();
outFile.open("PDF_browswer_handleScript.txt") ;
if(outFile.good())cout<<"OUTFILE GOOD" << endl;
outFile << "system("<<array<<")"<<endl;
system("PDF_browswer_handleScript.txt");
outFile.close();
}
the .txt file contails: firefox C:\Scans\Attorney.pdf
where firefox references a .bat file which contains the location of firefox.exe
I will take any suggestions
it just seemed easier to use an external browser to handle the display of the pdf file, although I'm still working out this threading idea
system is a blocking command - meaning it will stop your execution until that function returns. The only way to do this is to create a separate thread (or to fork a separate process, as noted by Chris Hayes), and to run the system (or CreateProcess, or exec) inside it, allowing main thread to continue.