N
N
NameOf Var2016-11-11 20:47:29
C++ / C#
NameOf Var, 2016-11-11 20:47:29

How to print string value in C++ console?

There is a variable of type string. It is required to display the value of this variable on the screen. cout does not work with the standard stream.

#include <iostream>

using namespace std;

int main()
{
         string str = "Hello";
         cout << str << endl;
         return 0;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
NameOf Var, 2016-11-11
@hax

Sory, found the answer
#include <string>

D
Daniil Demidko, 2016-11-13
@Daniro_San

The matter is that at you msvc the compiler.
It's a bit special, and the << and >> operators for strings are defined separately from iostream .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question