Jump to content


Strings & Classes


  • Please log in to reply
2 replies to this topic

#1 Guest_Max_Payne_*

Guest_Max_Payne_*
  • Guests

Posted 29 November 2007 - 06:37 PM

Menu.h

#pragma once

#include <iostream>
#include <cstring>

using namespace std;

class Menu
{
private:
	string title;

public:
	Menu( void );
	Menu( const Menu &unMenu );
	~Menu( void );

	void setTitle ( string title );
	string getTitle() const;
};


Menu.cpp

#include "Menu.h"

Menu::Menu(void)
{
	this->title = "Hello";
}

Menu::Menu(const Menu &unMenu)
{
	this->title = unMenu.title;

}

Menu::~Menu(void)
{
}

///////////////////////////////////////////////////

void Menu::setTitle( string title )
{
	this->title = title;
}

string Menu::getTitle() const
{
	return ( this->title );
}

main.cpp

#include "Menu.h"

#include <iostream>
#include <cstring>

using namespace std;

int main ()
{
	Menu m;

	m.setTitle( "Spider Man 3" );
	cout << m.getTitle();

	system("PAUSE");
	return 0;
}

I'm getting a problem when i put
cout << m.getTitle();

#2 CodeCat

CodeCat

    Half fox, half cat, and all insanity!

  • Members
  • 3,768 posts
  •  Fighting for equality of all species

Posted 29 November 2007 - 09:16 PM

<cstring> is for the char array style strings as used in C. If you want to use C++'s own string objects, you'll need <string> instead. <string> also declares some functions that are needed to be able to use <iostream> together with strings.
CodeCat

Posted Image
Posted Image

#3 Guest_Max_Payne_*

Guest_Max_Payne_*
  • Guests

Posted 07 December 2007 - 04:16 PM

Thank you that solved the problem.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users