VSCode cannot input data - c++

I'm a noob in C++ and I have VSCode running in Windows11 , with the typical extensions for C++ and MinGW. I am running a little code in this IDE:
#include <iostream>
using namespace std;
int main (){
int num;
cout << "Number: " ;
cin >> num;
return 0;
}
It is something basic for this test, but when I run it in the output option I cannot enter anything, neither letters nor numbers. Nothing comes up in the terminal option either. The code executes without errors and VSCODE does not give any information.
Instead, if I run the .exe file from outside the editor it works perfectly.
I don't know if it's my editor configuration error or some other problem, in Ubuntu or MacOS this has never happened to me.
I appreciate the help in advance.
All the best.

Related

Run C++ program in Terminal

I'm trying to run this simple C++ code in Sublime Text on Terminal but it's not exactly working...
#include <iostream>
using namespace std;
int main() {
cout << "Hello world!" << endl;
return 0;
}
I'm getting this message instead:
"hello_world2.cpp:1:10: fatal error: 'iostream' file not found"
How can I fix this?
You most probably are missing development headers for your C++ standard library.
You didn't say anything about your environment, but if you were on Windows on Mac you would for sure get these together with your compiler, so let's assume Linux.
You need to install libstdc++-devel package or equivalent (libstdc++-4.8-dev etc.)

Codeblocks won't run executable

somehow codeblocks decided not to run any new programs anymore. All I get is a black screen when running. Take for example the simple "Hello World" program. That will not even run. It compiles just fine without any error. All i see though when codeblocks opens is a black screen.
I tried looking online for help. It looked like this
Can't find file executable in your configured search path for gnc gcc compiler
would fix the problem. It didn't though.
This was my code:
#include <iostream>
using namespace std;
int main(){
cout<< "Hello World!" << endl;
return 0;
}
I don't know what happened and why. Sincerely hoping for an answer.

No output in c++-program if object is instantiated using Eclipse

I got an issue after installing Eclipse Kepler on my Windows 7 32bit machine. I installed the CDT and the MinGW-compiler. I configured the installation by adding MinGW to the PATH and tested my configuration with a "Hello world"-program, which worked.
The strange thing is, that if I instantiate an object, nothing is outputted. It doesn't matter if it's a std::string or a custom made class. If I instantiate it, nothing is outputted, even if it should be outputted before the instantiation. The exact same code works fine, if I compile it with cygwin gcc from command line. If I change the toolchain to cygwin gcc nothing changes (I've rebuild the program with "build all").
There is no error displayed and no problem listed.
Here's the minimal working example:
#include <iostream>
#include <string>
using namespace std;
class SayWorld{
public:
SayWorld(){
cout << "World!" << endl;
}
};
int main() {
//Only gets outputted, if the lines, that don't work are commented out:
cout << "Hello ";
// Works:
cout << "World!" << endl;
// Doesn't work:
// SayWorld sw;
// Also doesn't work:
// string str("World!");
// cout << str << endl;
return 0;
}
Edit 2:
I narrowed the error to MinGW, as this picture of a Cygwin-Bash-Terminal demonstrates. (The file was not changed beetween the to g++ calls and contains the example above)
Edit 1 (Legacy)
Toolchain-picture:
-picture removed- (don't think it was necessary)
After reinstalling eclipse and MinGW again, step-by-step following this video tutorial:
http://www.youtube.com/watch?v=77xZOT3xer4
and having the same problem afterwards, I stumbled uppon this post in the eclipse forum:
http://www.eclipse.org/forums/index.php/u/104305/
which has brought me to this solution:
Right-click Project -> Properties -> Run/Debug Settings
Choose executable and hit the "New"-button.
Go to the Environment-Tab and create a new variable named PATH with the value: "C:\MinGW\bin".
As I am no expert, I can't explain to you why it works, but it worked for me. If someone knows, how to do this better or wholly avoid this problem, I'd be glad to listen.
This entry was definitively in my Windows-PATH...
PS.: The problem seems also to be known here:
unable to see the output of c++ program in the console

cin crashes C++ program

I feel like this is a very rudimentary problem, but I can't seem to get cin working.
Using code as simple as this:
#include <iostream>
using namespace std;
int main ()
{
int i;
cout << "Enter a number: ";
cin >> i;
cout << i;
}
causes the program to crash. It compiles perfectly fine, but when I run it I get the program has stopped working dialog box. I'm using MinGW with the g++ commands to compile my code. I'm also running windows 8.1 if that has any effect whatsoever.
The code is perfectly fine. The issue is with the compiler. This generally happens because of the misconfiguration of linking files (DLL's). It is recommended that you uninstall the current installation and re-install the software by following the installation instructions. If you are looking for bundled alternatives then you can try Code::Blocks - http://www.codeblocks.org/.

Codeblocks outputs broken executable

I have downloaded plenty of different versions of code blocks, and none of them compiles quite right. My hello world runs within code blocks just fine. However, when I run the executable outside of codeblocks, it says "Hello.exe has stopped working". There isn't anything wrong with my code (I don't think.) and my mingw compiles fine outside of codeblocks. What does codeblocks do to my executable? Is there some option to fix this? I am on windows 7 64 bit, and my current code blocks version is 10.05. My program:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
cin.ignore();
return 0;
}
I solved the problem. I had a broken compiler (or something like that). My suggestion for other people with this problem is to experiment with different versions of the minGW compiler. Also, change the version of code blocks you are using, or even uninstall everything and restart. The problem with mine was I downloaded a bad compiler. [The truth is, codeblocks isn't the best ide.]