cout a string variable?

A little confused here, I'm getting this error.

http://i.imgur.com/PKJp2eF.jpg

EDIT: char* works for me, i'm not quite sure what strings are used for.

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

using namespace std;
int main()
{
    string str = "tester";
    cout << str << endl;
}
Last edited on
#include <string>
Thanks, I just figured that out.
It works fine for me
String is much more convenient than char*.
http://www.cplusplus.com/reference/string/string/

You need to include the necessary headers:
1
2
3
4
5
6
7
8
9
10
11
// you don't need cstdlib here
#include <string> // but you do use std::string
#include <iostream> // and std::cout and std::endl

// using namespace std; // avoid "use all"
int main()
{
    using std::string; // explicit using
    string str = "tester";
    std::cout << str << std::endl;
}
Topic archived. No new replies allowed.