[c++] how to print a string to console in c++

Im trying to print a string to console in c++ console application.

void Divisibility::print(int number, bool divisible)
{
    if(divisible == true)
    {
        cout << number << " is divisible by" << divisibleBy << endl;
    }
    else
    {
        cout << divisiblyBy << endl;
    }
}

i have the correct includes etc, this error i believe is just that i simply dont know how to print to console in c++ yet and this i guess isnt the way to do it

EDIT: sorry forgot to mention divisiblyBy is the string

This question is related to c++ console cout

The answer is


All you have to do is add:

#include <string>
using namespace std;

at the top. (BTW I know this was posted in 2013 but I just wanted to answer)


"Visual Studio does not support std::cout as debug tool for non-console applications"
- from Marius Amado-Alves' answer to "How can I see cout output in a non-console application?"

Which means if you use it, Visual Studio shows nothing in the "output" window (in my case VS2008)


Examples related to c++

Method Call Chaining; returning a pointer vs a reference? How can I tell if an algorithm is efficient? Difference between opening a file in binary vs text How can compare-and-swap be used for a wait-free mutual exclusion for any shared data structure? Install Qt on Ubuntu #include errors detected in vscode Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio 2017 errors on standard headers How do I check if a Key is pressed on C++

Examples related to console

Error in MySQL when setting default value for DATE or DATETIME Where can I read the Console output in Visual Studio 2015 Chrome - ERR_CACHE_MISS Swift: print() vs println() vs NSLog() Datatables: Cannot read property 'mData' of undefined How do I write to the console from a Laravel Controller? Cannot read property 'push' of undefined when combining arrays Very simple log4j2 XML configuration file using Console and File appender Console.log not working at all Chrome: console.log, console.debug are not working

Examples related to cout

undefined reference to 'std::cout' C++ printing boolean, what is displayed? 'cout' was not declared in this scope how to print a string to console in c++ How to print Unicode character in C++? cout is not a member of std How do I print out the contents of a vector? Why I cannot cout a string? How to print to console when using Qt 'printf' vs. 'cout' in C++