Randomly Run Failed with simple cout project - c++

When using this simple snippet
int main(int argc, char** argv) {
cout << "Joris" << endl;
return 0;
}
I get randomly this result:
Joris
or
RUN FAILED.
Behaviour occurs with internal terminal or standard output in project settings.
I run under openSUSE Netbeans 7.0.1 with GCC.

Do you get the same result with the following?
#include <iostream>
int main()
{
std::cout << "Joris" << std::endl;
return 0;
}

Related

problem with compiling a simple program with c++

I am really new to C++. I am trying to compile this simple program but I get an error
#include <iostream>
int main(int argc, char** argv)
{
cout << "You have entered " << argc
<< " arguments:" << "\n";
for (int i = 0; i < argc; ++i)
cout << argv[i] << "\n";
return 0;
}
The error that I get is
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
I try to compile it as g++ file1.cpp
I also tried
g++ -c file1.cpp and then g++ main.exe file1.o
which does not work as well.
What am I doing wrong?
Maybe try and create a new file in an empty directory name it if you want something like main.cpp and put the code in that you needed for namespace and everything else and run
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
cout << "You have entered " << argc
<< " arguments:" << "\n";
for (int i = 0; i < argc; ++i)
cout << argv[i] << "\n";
return 0;
}
It should work after and output a result
Maybe check out this medium article for more about why you need using namespace std
https://medium.com/breaktheloop/why-using-namespace-std-is-used-after-including-iostream-dc5ae45db652
You can try specify namespace like this ->
#include <iostream>
using namespace std;
EDIT 'must' replaced by 'can try'. It works but why !

missing output in the eclipse console when debugging

I recently started using Eclipse CDT (version 2019-03) with the Cygwin toolchain and have noticed some bizarre behaviour when using the debugger.
Under the debugger the following program behaves as you would expect
#include <iostream>
int main()
{
std::cout << "hello world\n" << std::flush;
}
However the following produces no output
#include <iostream>
int main()
{
std::cout << "* world\n" << std::flush;
}
And for the following the output is world
#include <iostream>
int main()
{
std::cout << "# world\n" << std::flush;
}
This behaviour is completely consistent and reproduceable. Does anyone have any explanation or workarounds?

when i use the c++ string in my code it compiles but i don't show an output

I don't know whether I have installed cygwin wrong or what but the code compiles fine but it doesn't show the output. Here's my code:
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
string name;
cout << "Enter the name of the person" << endl;
getline(cin, name);
cout << "Name is: " << name << endl;
return 0;
}
Here's the compilation image and the execution:
Your code is fine. The correct way to call the executable using Cygwin is ./string.exe
As I can see, you use cygwin. I had the same issue with gcc 5.2. Try to install gcc 4.9 and all corresponding libraries for this version instead.

Why boost::fiber blocks?

I'm trying to play with boost::fiber library but I have the problem with the "Hello, World" example. In the following code the program flow blocks after the fiber is finished and the main function never returns.
#include <iostream>
#include <boost/fiber/all.hpp>
using namespace std;
void helloFiber()
{
cout << "Hello, boost::fiber" << endl;
}
int main()
{
boost::fibers::fiber f(helloFiber);
cout << "Before join." << endl;
f.join();
cout << "After join." << endl;
return 0;
}
The result is:
Before join.
Hello, boost::fiber
I built boost::fiber current develop branch with the current develop branch of modular-boost. Is this behavior bug in the current implementation or there is something wrong in my usage?
your test app prints:
Before join.
Hello, boost::fiber
After join.
maybe you've checkout an broken version from branch develop
try this
int main()
{
boost::fibers::fiber f(helloFiber);
f.detach();
f.join();
return 0;
}
http://www.boost.org/doc/libs/1_58_0/doc/html/thread.html

GraphicsMagick code freeze in node addon (OSX)

I'm trying to make this simple GraphicsMagick example as a node binding/addon. This code works as expected in OSX 10.6.7 with GraphicsMagick 1.3.15
#include <Magick++.h>
#include <iostream>
using namespace std;
int main(int argc,char **argv)
{
Magick::InitializeMagick(0);
Magick::Image image;
try {
image.read( "snow.jpg" );
image.scale("320");
image.write( "snow-scaled.jpg" );
}
catch( Magick::Exception &error_ ) {
cout << "Caught exception: " << error_.what() << endl;
return 1;
}
cout << "Image scaled!" << endl;
return 0;
}
Compiling:
g++ scale.cpp `GraphicsMagick++-config --cppflags --cxxflags --ldflags --libs`
Running:
./a.out
Image scaled!
But making this code a node binding (0.6.14) just freezes (see full gist):
void AsyncWork(uv_work_t* req) {
std::cout << "AsyncWork..." << std::endl;
Baton* baton = static_cast<Baton*>(req->data);
baton->result = 12345; // Just a test
Magick::Image image; // <--- Freezes here!
image.read("snow.jpg");
std::cout << "Scaling..." << std::endl;
image.scale("200");
std::cout << "Done!" << std::endl;
image.write("snow-scaled.jpg");
// and baton->error to true.
}
Output when calling it from javascript:
AsyncWork...
Any ideas what's wrong?
On a side note, this actually works when compiled/run under Ubuntu!
Have you tried to initialise with Magick::InitializeMagick(0); in AsyncWork? Asynch functions run on pool threads.
You could always just git the finished GM addon here.