| | |
Strings & Classes
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Menu.h
Menu.cpp
main.cpp
I'm getting a problem when i put
cout << m.getTitle();
C++ Syntax (Toggle Plain Text)
#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
C++ Syntax (Toggle Plain Text)
#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
C++ Syntax (Toggle Plain Text)
#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();
•
•
Join Date: Nov 2007
Posts: 19
Reputation:
Solved Threads: 3
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.
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.
•
•
•
•
<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>.
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.
•
•
•
•
I would appreciate some help in this thread:
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.
I know I am. Therefore I am.
![]() |
Similar Threads
- yyy65&XBDYUS.htm annoyance!!!! (Viruses, Spyware and other Nasties)
- Trojan Horse Downloader.small.44.bw & 44.j (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: how to compile a program
- Next Thread: strings with vs2008
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






