How to cout a message inside a function other than main

Hello,

I can only print a message, via std::cout, when I'm in main(). However, when I'm inside a function other than main, std::cout does not work. How can I achieve this ? Thanks!
Compile and run this code. Does it print the message?

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

void print() 
{ 
    std::cout << "I'm an output message.\n";
}

int main() 
{
    print();
}
Topic archived. No new replies allowed.