Trouble printing string member variable.

Currently when the attempt to print creature01.name is made, the console is blank, so it seems that the string is just not printing. It works when I use int member variables instead so I'm struggling to find some logic as to why this is happening.

What I want to happen in this example is for the console to print, "wew".

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "stdafx.h"
#include <iostream>
#include <string>

class creatures {
public:
	std::string name;

	void setName(std::string nam){
		nam = name;
	}
};

void main()
{
	creatures creature01;

	creature01.setName("wew");

	std::cout << creature01.name;

	std::cin.get();
	std::cin.get();
}
Last edited on
Line 10 should be
name = nam;


Line 14 should be
int main()
Topic archived. No new replies allowed.