Below are my errors
_______________________________________________________
prog.cpp:25:2: error: expected unqualified-id before ‘else’
else
^
prog.cpp:27:12: error: expected ‘;’ after class definition
}
^
prog.cpp: In constructor ‘MyString::MyString(const char*)’:
prog.cpp:14:43: error: ‘strlen’ was not declared in this scope
Buffer = new char [strlen(InitialInput)+1];
^
prog.cpp:15:32: error: ‘strcpy’ was not declared in this scope
strcpy(Buffer, InitialInput);
^
prog.cpp: In copy constructor ‘MyString::MyString(const MyString&)’:
prog.cpp:22:46: error: ‘strlen’ was not declared in this scope
Buffer = new char [strlen(CopySource.Buffer)+1];
^
prog.cpp:23:35: error: ‘strcpy’ was not declared in this scope
strcpy(Buffer, CopySource.Buffer);
^
prog.cpp: At global scope:
prog.cpp:28:22: error: declaration of ‘~MyString’ as non-member
~MyString()
^
prog.cpp: In function ‘int GetLength()’:
prog.cpp:34:28: error: ‘Buffer’ was not declared in this scope
return strleng(Buffer);
^
prog.cpp:34:34: error: ‘strleng’ was not declared in this scope
return strleng(Buffer);
^
prog.cpp: In function ‘const char* GetString()’:
prog.cpp:37:20: error: ‘Buffer’ was not declared in this scope
return Buffer;
^
prog.cpp: At global scope:
prog.cpp:39:1: error: expected declaration before ‘}’ token
};
^
prog.cpp: In function ‘int GetLength()’:
prog.cpp:35:12: warning: control reaches end of non-void function [-Wreturn-type]
}
^
prog.cpp: In function ‘const char* GetString()’:
prog.cpp:38:12: warning: control reaches end of non-void function [-Wreturn-type]
}
^
Have you tried to understand the compiler error messages? They tell you what is wrong.
Line 25: You have an else statement, but it's not associated with an if statement.
Lines 26-27 are extraneous.
Line 31: Lose the =
Line 34: strlen misspelled.
Line 56: MyString misspelled.
Line 60: sizeof misspelled.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
I am not sure which compiler you are using, but if you double click the error, it will take you to the line with the error. Sometimes its not exactly correct, but usually it is. I know that visual studio 2013 professional will do this. But as Abstraction has mentioned, you have to read the errors and make sense of them. They do tell you what is wrong. They may not tell you how to fix them, but you can usually figure out why your getting the error based on what it says.