C++ output window not working as expected - c++

ok so I just started learning today, This simple code works as expected when I run it in the integrated terminal but not in the output window, I'm not able to type in the numbers, any suggestions on how to solve the issue ?
Executed in output window
Executed in terminal window

As described in this Question: Cannot edit in read-only editor VS Code. The VS Code Output window is read-only. So you cannot input any values there. And as your code requires input, it will only work in a terminal (as you can input values there).

Related

Console not working for a command line app in Xcode

I'm used to using Xcode for my C++ class homework. I usually just create a command line project, write code, and test it with the console that appears at the bottom of the window. But since I updated Xcode (it's now 8.3.1), I can't make the console appear when I run my command line app. This question seems to have come up before, and I followed the instructions here, but the console is weird. For example, I wrote a simple function, and then the main program. The console wouldn't do anything until I first typed a number, and then it used my input as the parameter for the function. That's not how it's supposed to work. The console didn't give the prompt or anything. The main program worked, but only because I knew the program. Someone else who didn't know how it worked would simply see a blank console.

C++ output in browser

I have a C++ program that runs nicely and it gives my output in the terminal when it runs, this is handy if the algorithm takes time.
How do I 'cout' the output in a terminal styled div in the browser (doesn't allow user to type into it as an actual terminal)
Alternatively is there a different C++ command to direct output elsewhere other than the terminal window in which it is currently running?
Kind of new to C++ so maybe this is a obvious fix but thanks anyway

Clearing Screen in C++/XCode

I am trying to write up a C++ program for a class using XCode. One of the things I wish to do, is to simply clear the screen. I've looked into how to do this, however the catch is that the code needs to run on both a Windows and Macintosh computer. I've looked at some other similar questions, but none of the answers help me. I know there is no "screen" but I want the system to clear the output window. I know that the command system("clear"); does what I want it to, but when XCode tests the program, instead of clearing the screen it prints TERM Variable not set
I've tried opening up the terminal and typing clear and it does in fact respond the way I want it to, so why doesn't the 'terminal' inside of XCode do the same? I just want to get the output window in XCode to respond to clear the same way that the terminal already does.
Here is something I have already tried;
I went to the terminal and ran echo $TERM, to which the terminal responded xterm-256color. I then went over to XCode and opened the "Scheme" settings, and found an Environment Variables setting under "Arguments". I added a variable (to the blank list) called TERM and gave it value xterm-256color. Upon running the program again, the output displays ¿[H¿[2J in the output window, positioned where the TERM Variable not set used to be printed.
Last thing, as a reminder, I cannot change the source code from the way it is now, or it could cause errors when the program is run on a Windows machine.
It does not work because you are "lying": The terminal in Xcode is not a xterm-256color, but it is dumb terminal. More precise, the display represents a NSTextStorage that collects stdout and/or (depending on target switch) stderr.
A dumb terminal is not able to clean the display. If you want to change this, you can write a plug-in similar to Xcode-Colors what adds the ability to understand ansi color codes.
However, if your requirement that the code simply run at Windows and OSX, you may stick with your solution system("clear"), since it works prefectly in the "normal" OSX terminal.

Why does my Codeblock only display output for less than second..?

I installed Codeblock a week ago and have not changed any setting. I created a simple console application and when I clicked build and run it display my output for like milisecond and disappear... It used to stay forever until I exit it. Anyone know why is this happening? In the Build log tab it says "Process terminated with status 0 (0minnutes, 0 seconds)
You don't have any problem actually, neither in your Codeblocks Application nor in your code, But codeblocks doesn't wait for you to close its console window manually, It automatically does it.
You've 3 ways, choose that suits you better
Go to Menu Bar and toggle 'show output window'
Alternatively you can append a C++ code that waits for an event to happen, so that you may get enough time to watch your Output.
You can use the code which I've given below
It will be definitely good if you choose to see your output message through debugging(Step Over). It will also improve your debugging skills.
If you want to choose second approach then append following code in your application
#include<conio.h>
int main()
{
// After your code - write
getch();
return 0;
}
Note:- I believe you're using codeblocks on Windows Platform, this code will work fine on windows, but <conio.h>
won't be available to you if you want to port your program from Windows to Linux
I'll recommend you to give them preference in this order [3 > 1 > 2]
for those who may encounter this error:
all you need to do to make the console not dissapear is this:
go to project properties.
click on build targets
there is an option below console application "pause when execution ends"
check it and you are good to go!
Hope this helps
Use :
#include <iostream>
//...other includes....
int main()
{
/*Your Code */
//...
std::cin.ignore(); //wait for Enter, will makes the console to stay.
}
You may be clicking on the red arrow, however click on the "build an run" arrow instead, which has a little cog and a green arrow.
Solution if you are copying and pasting input: For me, the issue was that I was copying and pasting my input file from the web. Presumably, this copied some invisible characters, such as a return, which my program registered as the user having pressed any key to continue. The solution I used was to download the file to my computer, then run my program in command prompt, piping the input into the .exe file in the following manner:
C:\Project Directory> myProgram.exe < myInputFile.txt
Many of my professors recommend running programs from the command line, and I advise using this tactic as it is quick and lets you skip manual typing. Also, you can save the output of your program to a desired file, rather than having it print on the command line, by doing the following:
C:\Project Directory> myProgram.exe < myInputFile.txt > programOutput.txt
Hope this helps.

calling c++ from python IDLE issue

i am new to python and am trying to call a c++ function from python, I cam across this answer from Florian Bösch and found it really helpful, i did everything as in the link but i have a small problem which really surprised me, when i run the fooWrapper.py from command prompt it displays the result "hello" but when i run the program from idle by clicking run as module the python shell opens and displays nothing, only action is the cursor moves down as when you press enter. Is this normal or is this a problem???
I use python 2.7.3(32bits),with windows 7 and MInGW complier.
The problem is that IDLE redirects standard input and output, but your C++ function writes to the original standard output and thus IDLE will not show it. If you launch IDLE from a terminal you will see the C++'s output in the terminal.
It's a problem of IDLE, and I doubt that you can do something about it.
If you want to develop something bigger than a really small script you ought to use a different IDE.