Ask Your Question
0

cout doesn't print to console

asked 2018-05-18 14:21:40 -0600

raisa_ gravatar image

I'm working with OpenCV and C++. Have set up my project correctly, testing it by calling and displaying image, it succeed. Now I'm following simple basic tutorial for beginner and my code won't show up.

Here's the code

#include <iostream>
#include "opencv2\opencv.hpp"

using namespace std;
using namespace cv;

double square(double x) {
    return x*x;   }

void print_square(double x) {
    cout<<"Square of "<< x <<"is "<<square(x)<<endl; }

int main (int argv, char** arc) {
    print_square(2);
    waitKey(0);
}

I have also carefully set my project as Console project, still nothing show on the console. There's no error as well. Any advice ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-05-19 01:45:01 -0600

berak gravatar image

updated 2018-05-19 01:45:57 -0600

Square of 2is 4

can it simply be, that you're running this from VS, and the console window closes, before you can see the output ?

btw, note, that waitKey() only has an effect, if there's a highgui window. without that, try a

int k;
cin >> k;

instead. (or run your exe from a cmdline, not your IDE)

edit flag offensive delete link more

Comments

Hi, thanks! Yes the window closes before I see any output. Also in this case, I don't need the user to input the number using cin. I'm just trying to call the method.

raisa_ gravatar imageraisa_ ( 2018-05-20 07:58:11 -0600 )edit

system("pause"); will also block nicely ;)

also, the problem will go away, once you start working with images, webcam, imshow() and such.

berak gravatar imageberak ( 2018-05-20 08:13:03 -0600 )edit

this one works !! thanks a lot !

raisa_ gravatar imageraisa_ ( 2018-05-20 08:14:51 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-05-18 14:21:40 -0600

Seen: 802 times

Last updated: May 18 '18