Here is another small problem possibly brought about by the ancient book I am using to learn or something I did. I am trying to get my destructor to print a few lines but everytime I run the program he destructor simply does not do what its told and display the few lines. here is the code: Code: #include <iostream> #include <string.h> using namespace std; class Stringthings { private: char str[20]; char firstletter; char lastletter; public: void first(void); void show(void); void last(void); Stringthings(char s[20]); ~Stringthings(void); }; //Functions of the class void Stringthings::first(void) { if(strlen(str)<1) firstletter = '?'; else firstletter = str[0]; } void Stringthings::show(void) { cout << firstletter << endl; } void Stringthings::last(void) { if(strlen(str) < 1) lastletter = '?'; else lastletter = str[strlen(str) - 1]; } //This constructor creates a stringthing object and copies the input string into the private data member str // strcpy is in the library string.h Stringthings::Stringthings(char s[20]) { strcpy(str, s); } Stringthings::~Stringthings(void) { cout << endl << "The full string was " << str; cout << endl << "That's all folks!" << endl << endl; } int main(void) { char data[20]; cout << "Enter the string: "; cin.getline(data, 20); Stringthings test(data); test.first(); test.show(); cin.ignore(256, '\n'); cout << "Press ENTER to continue..." << endl; cin.get(); return 0; } no errors pop up the machine simply runs the default destructor and not the one I created Thanks much Bill
I have done that for you and here is the link on how to do that - http://www.cfanatic.com/misc.php?do=bbcode#code
Dunno what's wrong on your system, it worked fine for me: ---START Enter the string: hello h Press ENTER to continue... The full string was hello That's all folks! ---STOP I had to press Enter to continue before it said "press enter to continue" (although not if I entered a very long string). What string did you enter? What output did you get? Did the program end or did it appear to hang?