Code:
/* Filename: Simple.h */
/* These 2 lines below, and the final one at the bottom are recommended.
* You should include them in all your header files so functions/data types
* don't get defined (#included) twice.
*/
#ifndef YOUR_HEADER_NAME_DEFINED
#define YOUR_HEADER_NAME_DEFINED
/* put #defines, #includeds, const values, classes,
* typedefs and prototypes here */
#include <iostream>
#include <cstring>
using std::cout;
using std::strcpy;
class Simple
{
private:
char * str_;
public:
Simple(const char* str) { strcpy(str_, str); }
char* getString() { return str_; }
void print() const { cout << str_ << '\n'; }
};
#endif
Code:
/* Filename: main.cpp */
#include "Simple.h"
int main()
{
Simple string1("I am a string!");
string1.print();
return 0;
}
If you're using Linux, make sure the two files are in the same directory and use g++ to compile:
Code:
[shell]$ g++ -o Simple main.cpp
[shell]$ ./Simple
I am a string!
[shell]$