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();
}
Related
I have a weird problem when trying to print out the content of a vector.
I'm using Visual Studio Code with the CMake extension.
I can print out simple text using cout
#include <iostream>
#include <vector>
using namespace std;
int main() {
cout << "test" << endl;
return 0;
}
But I can't print out the vectors content
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> test = {1,2,3};
cout << "test" << endl;
cout << test[1] << endl;
return 0;
}
I've never really worked with C++ vectors, so I'm probably missing something fairly obvious but I followed a C++ vector tutorial step by step and for them, the output works fine.
Cheers,
Luca
I'm new to C++ and have exactly the same problem.
Temporary workaround as posted by Luckylone here
would be to copy libstdc++-6.dll from your mingw64\bin folder into your project folder.
Something is messing up our link with the resources even though folders are properly added to system PATH.
EDIT: After an afternoon of troubleshooting, I've solved my problem by uninstalling compilers (originally provided through WinLibs) and reinstalling them using MSYS2.
Delete the existing Mingw64 folder, remove the PATH variables, then carefully follow these instructions. Keep in mind that I had to add mingw64/bin to both user and system Path, and restart VS Code before damn std::vector finally started to print.
I'm using the following application
#include <iostream>
using namespace std;
void print(char* s)
{
cout << s << endl;
}
int main(int argc, char* argv[])
{
print("a");
print("b");
print("***");
print("c");
print("d");
}
When I run it with the debugger under VSCode (using "Native Debug" extension), it never pass the second print and this is my output:
a
b
It never pass print("***), even if I put a breakpoint after that line it doesn't reach it.
if I comment out print("***"), the application finish with the correct output:
a
b
c
d
The only thing I managed to figure out is that there is and issue printing "*" character and if I replace it with any other character all works fine. Why do I see this behavior and how can I fix this without having to change the code?
#molbdnilo, seem to be correct. It looks like a bug in "Native Debug" extension. The problem is not reproduced when another extension is used (I tried with Microsoft's "C/C++" extension)
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?
I am new to C++ and trying my hands on std::vector. But for some reason even a single std::cout doesn't work with the vector I have declared.
Here is the sample code:
#include <iostream>
#include <vector>
using namespace std;
int main(){
std::vector <int> test_score;
test_score.push_back(10);
cout << test_score.at(0);
return 0;
}
The terminal output shows nothing. Here it is.
The same code works fine on IDEs like CodeBlocks.
Just for your info, your code works fine on my terminal without the image description part.
Maybe try to comment these lines out as they are not involve in the problem or try to compile a Hello World program first may help.
I'm following some C++ tutorials and have started experimenting with structures, however a test structure I built is not behaving as intended. I have tried running it a few times and all it outputs is (11db), and when I try rerunning it I get a window saying that the product is already running.
Here is the code...
#include <iostream>
using namespace std;
int main(){
struct Address {
int streetNum;
string streetName;
};
Address myHouse;
myHouse.streetNum = 911;
myHouse.streetName = "Inverness Street";
cout << myHouse.streetName << endl;
return 0;
}
I would expect the output to be "Inverness Street". Why am I getting an error instead?
EDIT ** Bonus points for anyone who can tell me how to remove a missing file warning? I removed a useless file that was created as a means to find my way around creating different types of files, but since I deleted it I have had a warning in the file that it once shared a folder with.