Click here to Skip to main content
15,890,557 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralExcel automation Pin
Anonymous21-May-04 23:02
Anonymous21-May-04 23:02 
Generalusing autoshape in dhtmleditor control Pin
senthil_kumar_project21-May-04 22:58
senthil_kumar_project21-May-04 22:58 
GeneralAdding to a number in a text file. Pin
contemptx21-May-04 22:47
contemptx21-May-04 22:47 
GeneralRe: Adding to a number in a text file. Pin
David Crow22-May-04 17:21
David Crow22-May-04 17:21 
QuestionHow to dock a dialogbox ! Pin
Shailesh Ha21-May-04 22:02
Shailesh Ha21-May-04 22:02 
AnswerRe: How to dock a dialogbox ! Pin
Kamyar Souri22-May-04 5:49
Kamyar Souri22-May-04 5:49 
QuestionHow to implement autoshapes in dhtml editor Pin
Member 52815521-May-04 20:54
Member 52815521-May-04 20:54 
Generalwhere did I do wrong? (myString class) Please help! I have to turn in tomorrow Pin
foxele21-May-04 18:45
foxele21-May-04 18:45 
I wrote a string class and try to test with a very simple driver program, but there are some erros, can somebody help me figure out my mistakes?

thank you!

--------------Configuration: main - Win32 Debug--------------------
Compiling...
main.cpp
Linking...
main.obj : error LNK2001: unresolved external symbol "public: __thiscall myString::~myString(void)" (??1myString@@QAE@XZ)
main.obj : error LNK2001: unresolved external symbol "class ostream & __cdecl operator<<(class ostream &,class myString const &)" (??6@YAAAVostream@@AAV0@ABVmyString@@@Z)
main.obj : error LNK2001: unresolved external symbol "public: __thiscall myString::myString(char const *)" (??0myString@@QAE@PBD@Z)
Debug/main.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.

main.exe - 4 error(s), 0 warning(s)
____________________________________________________________________________

myString.h file:

//myString

#ifndef MYSTRING_H
#define MYSTRING_H

#include<iostream.h>

class myString{

friend ostream &operator<<(ostream &, const myString &);
friend istream &operator>>(istream &, myString &);

public:

myString( const char * = "");
myString(const myString &);
~myString();
const myString &operator= (const myString &); //assign string
myString &operator+= (const myString &);
int operator! () const; //empty string
int operator== (const myString &) const;
int operator!= (const myString &) const;
int operator< (const myString &) const;
int operator> (const myString &) const;
int operator>= (const myString &) const;
int operator<= (const myString &) const;
char &operator[] (int);
myString &operator()(int, int);
int getLength() const;
// void toUpper (myString &);
// void toLower (myString &);

private:
char* sPtr;
int length;
};

#endif
________________________________________________________________________

myString.cpp file

//myString.cpp

#include<iostream.h>
#include<string.h>
#include<assert.h>
#include"myString.h"

myString::myString(const char *s)
{

lengh = strlen(s);
sPtr = new char[lengh +1];
assert(sPtr!=0);

strcpy(sPtr, s);
}
//convention constructor
myString::myString(const myString ©)
{
lengh = copy.length;
sptr = new char [length +1];
assert(sPtr!= 0 );
strcpy(sPtr, copy.sPtr);
}
//copy constructor
myString::~myString()
{
delete [] sPtr;
}
//destructor

const myString &myString::operator = (const myString &right)
{
if(&right! = this)
{
delete [] sPtr;
length = right.length;
sPtr = new char [length+1];
assert (sPtr!= 0);
strcpy(sPtr, right.sPtr);
}
else
cout<<"Attempted assignment of a String to itself\n";

return *this;
}
//operator =

myString &myString::operator+= (const myString &right)
{
char * tempPtr = sPtr;
length+= right.length;
sPtr = new char [length +1];
assert(sPtr!= 0);
strcpy(sPtr, tempPtr);
strcat(sPtr, right.Ptr);
delete[] tempPtr;
return *this;
}
//operator +=

int myString::operator! () const{return length == 0;}//empty

int myString::operator == (const String &right) const
{
return strcmp(sPtr, right,sPtr) == 0;
}

int myString::operator!= (const myString &right)const
{
return strcmp(sPtr, right.sPtr)!= 0;
}

int myString::operator< (const myString &right) const
{
return strcmp (sPtr, right.sPtr) < 0;
}

int myString::operator> (const myString &right) const
{
return strcmp (sPtr, right.sPtr) > 0;
}

int myString::operator>= (const myString &right) const
{
return strcmp (sPtr, right.sPtr) >= 0;
}

int myString::operator<= (const myString &right) const
{
return strcmp (sPtr, right.sPtr) <= 0;
}

char &myString:: operator[](int subscript)
{
assert(subscript >= 0 && subscript< length);

return sPtr[subscript];
}


myString &myString::operator() (int index, int subLengh)
{
assert(index >=0 && index<length &&sublength="">=0);

myString *subPtr = new myString;

assert(subPtr! = 0);

int size;

if((subLength == 0)||(index + subLength > length))

size = length - index+1;

else

size = subLength +1;

delete subPtr->sPtr;
subPtr->length = size;
subPtr-> = new char[size];
assert(subPtr->sPtr!=0);

for(int i = index, j = 0; i<index+size-1; i++,j++)
="" subptr-="">sPtr[j] = sPtr[i];

subPtr->sPtr[j] = '\0';

return *subPtr;
}

int myString::getLength()const{return length;}


ostream &operator<< (ostream &output, const myString &s)
{
output<<s.sptr;
return="" output;
}

istream="" &operator="">> (istream &input, myString &s)
{
static char temp[100];
input>>temp;

s=temp;

return input;
}

________________________________________________________________________

very simple main :


#include <iostream.h>
#include "myString.h"
#include <string.h>

int main()
{

myString s1("happy");




cout<
GeneralRe: where did I do wrong? (myString class) Please help! I have to turn in tomorrow Pin
Maxwell Chen21-May-04 21:39
Maxwell Chen21-May-04 21:39 
GeneralRe: where did I do wrong? (myString class) Please help! I have to turn in tomorrow Pin
foxele21-May-04 22:00
foxele21-May-04 22:00 
GeneralRe: where did I do wrong? (myString class) Please help! I have to turn in tomorrow Pin
foxele21-May-04 22:05
foxele21-May-04 22:05 
GeneralRe: where did I do wrong? (myString class) Please help! I have to turn in tomorrow Pin
Maxwell Chen21-May-04 22:11
Maxwell Chen21-May-04 22:11 
GeneralRe: where did I do wrong? (myString class) Please help! I have to turn in tomorrow Pin
Maxwell Chen21-May-04 22:07
Maxwell Chen21-May-04 22:07 
GeneralRe: where did I do wrong? (myString class) Please help! I have to turn in tomorrow Pin
foxele22-May-04 17:21
foxele22-May-04 17:21 
GeneralRe: where did I do wrong? (myString class) Please help! I have to turn in tomorrow Pin
Maxwell Chen22-May-04 22:18
Maxwell Chen22-May-04 22:18 
Generalcreating an application that runs in the background Pin
shals16921-May-04 18:36
shals16921-May-04 18:36 
GeneralRe: creating an application that runs in the background Pin
Dominik Reichl22-May-04 0:53
Dominik Reichl22-May-04 0:53 
Generalbinary contents in a CString Pin
(Steven Hicks)n+121-May-04 17:54
(Steven Hicks)n+121-May-04 17:54 
GeneralRe: binary contents in a CString Pin
Andrew Quinn AUS21-May-04 22:57
Andrew Quinn AUS21-May-04 22:57 
GeneralRe: binary contents in a CString Pin
Prakash Nadar22-May-04 2:10
Prakash Nadar22-May-04 2:10 
GeneralRe: binary contents in a CString Pin
Gary R. Wheeler23-May-04 12:35
Gary R. Wheeler23-May-04 12:35 
GeneralRe: binary contents in a CString Pin
(Steven Hicks)n+123-May-04 13:06
(Steven Hicks)n+123-May-04 13:06 
General32 bpp images w/ controls Pin
alex.barylski21-May-04 16:39
alex.barylski21-May-04 16:39 
GeneralRe: 32 bpp images w/ controls Pin
Prakash Nadar21-May-04 16:43
Prakash Nadar21-May-04 16:43 
GeneralRe: 32 bpp images w/ controls Pin
John R. Shaw22-May-04 17:14
John R. Shaw22-May-04 17:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.