954,219 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Strings & Classes

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

Max_Payne
Light Poster
32 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

Use
#include
instead of
#include

danzona
Newbie Poster
19 posts since Nov 2007
Reputation Points: 10
Solved Threads: 3
 
Use #include instead of #include

That Fixed the Problem. Thanks

can you tell me what's the difference between
&

When do we use each one ?

I only know that is more recent.

tx.

Max_Payne
Light Poster
32 posts since Oct 2007
Reputation Points: 10
Solved Threads: 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.

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

The quick answer is that is the C++ version of the old C header file string.h, while 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 is newer, and it just goes to show that newer is not always better.

danzona
Newbie Poster
19 posts since Nov 2007
Reputation Points: 10
Solved Threads: 3
 

aka 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 instead of .

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 

aka 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 instead of .

" aka 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.

Aashath
Newbie Poster
18 posts since Dec 2007
Reputation Points: 11
Solved Threads: 5
 

No, this is C++. Refer to old files like as .

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

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 

I would appreciate some help in this thread:
http://www.daniweb.com/forums/thread101965.html

Max_Payne
Light Poster
32 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 
I would appreciate some help in this thread: http://www.daniweb.com/forums/thread101965.html

The right place to ask about this is http://www.daniweb.com/forums/thread101965.html
The code is too big to read. Why dont you zip and upload the project and indicate the problem function. It will be easy to debug.

dubeyprateek
Junior Poster
176 posts since Mar 2006
Reputation Points: 39
Solved Threads: 24
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You