0

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();

6
Contributors
9
Replies
12
Views
10 Years
Discussion Span
Last Post by dubeyprateek
0

Use
#include <string>
instead of
#include <cstring>

That Fixed the Problem. Thanks

can you tell me what's the difference between
<cstring> & <string>

When do we use each one ?

I only know that <cstring> is more recent.

tx.

0

cstring replaces string.h which is where a lot of the standard functions to manipulate C style strings (null terminated char array) are located. string is the header for the STL string class and it contains the functions to manipulate STL string objects.

0

The quick answer is that <cstring> is the C++ version of the old C header file string.h, while <string> is the std::string class from C++.

There is probably a long answer about the history of C and C++ and MFC and OLE, and it probably has something to do with Unicode but it is beyond my knowledge.

I'll take your word for it that <cstring> is newer, and it just goes to show that newer is not always better.

0

<cstring> aka <string.h> is not more recent. It is the old C string stuff.

The only thing that is recent about it is the ability to refer to it as <cstring> instead of <string.h>.

0

<cstring> aka <string.h> is not more recent. It is the old C string stuff.

The only thing that is recent about it is the ability to refer to it as <cstring> instead of <string.h>.

" <cstring> aka <string.h> is not more recent. It is the old C string stuff."

Is that the CString thats available in MFC is also the same the old C string stuff. Is Microsoft reinvented the wheel or its their own implementation.

0

No, this is C++. Refer to old files like <string.h> as <cstring>.

Microsoft's CString is older than std::string, but far more recent than the old C-style string handling routines.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.