String in class (separate file) not working

+3 Y S · February 27, 2015
I'm trying to do Bucky's 46 and 47th C++ tutorials on composition, but I keep getting errors about the strings. I'm using visual c++  2010 express. I threw together a really short piece of code solely to test if strings in classes will work, and it didn't. Thank you in advance for any replies, I'll check back in a bit.

// MyString.h : class I made

#pragma once
ref class MyString
{
public:
MyString(void);
string name;
};

// MyString.cpp : class I made

#include "StdAfx.h"
#include "MyString.h"
#include

MyString::MyString(void)
: name("bob")
{
}

// Testing Class Strings.cpp : main project file.

#include "stdafx.h"
#include "MyString.h"
#include
using namespace std;

using namespace System;


int main()
{
    MyString obj;
    cout<<obj.name;
    system("pause");
    return 0;
}


Post a Reply

Replies

Oldest  Newest  Rating
0 OLayemii Garuba · March 8, 2015
type "using namespace std;" in the header file and retry!!
  • 1

C++

107,194 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator