When the program built with C::B doesn't work - c++

I made a small c++ project and it was fully compiled and built it.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
When I run through c::b it was okay
However, it says next warnings when I run program outside of the c::b.
"programdir/bin/Debug/program.exe"
So I got "libgcc_s_dw2-1.dll" from sourceforge, pasted it next to my .exe file,
and I got 0xc000007b error with the error "cannot start the program"
What should I do in this case of problem?

Related

C++ cout is not printing to command prompt

I'm getting started with C++ and am trying to work with vectors and printing stuff. I am using Windows 10, writing my code in Visual Studio Code, I just downloaded the MinGW-g++ compiler, and am trying to run my code in CMD.
This is my code, I've tried printing different things, and it's not even printing this "Hello". I've also tried using << endl; which also prints nothing. I also tried adding and remove a "return 0;" at the end but it changed nothing. The program compiles just fine. Any advice?
#include <iostream>
using namespace std;
int main(void)
{
std::cout << "Hello";
std::cout.flush();
}

Declaring multiple ifstream makes code crash

I just installed mingw on my Windows 10 computer and wanted to code a program that read two files. I immediately faced a frustrating bug with ifstream: when I declare more than one ifstream, the program seems to crash (nothing is logged although the first line cout some text).
The following code compiles and logs "test" in the console:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
cout << "test" << endl;
ifstream test;
return 0;
}
The following code compiles but seems to crash at runtime, nothing is logged:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
cout << "test" << endl;
ifstream test;
ifstream test2;
return 0;
}
I tested the exact same codes on a macOS Mojave and both codes work and log "test".
I guess the issue is related to the g++ installation but I'd like to know what's really happening and how I can fix this on Windows.

Visual Studio 2017 "Unable to start program. The system cannot find the file specified"

I'm following this tutorial to create a C++ Hello World app for Visual Studio.
https://tutorials.visualstudio.com/cpp-console/install
I've installed the software, selected "Windows Console Application" and copy/pasted the Hello World program from the tutorial:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, world!\n";
return 0;
}
However, when I try to run the Local Windows Debugger, I get this error:
Unable to open program.
\repos\HelloWorld\Debug\HelloWorld.exe
The system cannot find the file specified.
How would I include an .exe file?
Also, I have an error "cannot open stdafx.h", but I assume that's connected to this.
EDIT:
I removed "#include "stdafx.h"" and got the same error. It also said there was an unexpected end of file and suggested I #include "pch.h", so I did.
#include <iostream>
#include "pch.h"
using namespace std;
int main()
{
cout << "Hello, world!\n";
return 0;
}
I'm still getting the error that it can't find .exe ...also 'cout' is an undeclared identifier.

Eclipse CDT using std libraries in external console

I created C++ console project in Eclipse on Windows 7. I wanted it to run in external terminal, so I configured External Tool as described here: LINK. The following code runs fine and shows "Hello" on the console:
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
void foo() {
//queue<char> x;
}
int main() {
//vector<int> a;
//string t;
cout << "Hello World!" << endl;
cin.get();
return 0;
}
However, when I uncomment one of the lines above, external console refuses to work (program exits instantly). Program compiles successfully and runs in the internal console.
The variables do not have to be used, declaration is sufficient to stop excution. I assume, there is something wrong with the External Tool, as the internal console works normally (maybe I should add some libraries to working directory).
Any ideas?

Microsoft visual studio 2012 c++

I am learning c++ from scratch and I was trying to make hello world program with this code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}
but I always end with "this project is out of date"
and when I try to build it I have this error message:
unable to start program 'c:\users\User\documents\visualstudio2012\projects\Consoleapplication3\Debug\ConsoleApplication3.exe'.
the system cannot find the file specified
Your program should fail if you do not include your default #include <iostream>, which implies that your code should be something like this:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}
These said, to fix your problem, look in the solution explorer box to the left. Make sure that there is actually a .cpp file there. You can do the same by looking the .cpp file where the .sln file for the project is stored. If there is not one, then you will get that error.
When adding a cpp file you want to use the "add new item" icon. (top left with a gold star on it, hover over it to see the name) For some reason Ctrl+N does not actually add a .cpp file to the project.
Sources : System cannot find specified file