please help (novice)
From: ranger (sgrine_at_msn.com)
Date: 11/20/04
- Next message: Gary Labowitz: "Re: please help (novice)"
- Previous message: Michael Post: "Re: ftp-connection under dos6.2"
- Next in thread: Gary Labowitz: "Re: please help (novice)"
- Reply: Gary Labowitz: "Re: please help (novice)"
- Reply: Dirk Feytons: "Re: please help (novice)"
- Reply: Alf P. Steinbach: "Re: please help (novice)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 20 Nov 2004 11:22:23 -0800
Hi,
I'm a beginner with C++, studying on my own from a book and I've
encoutered quite some problems.. If possible, someone out there might
help me out..
The problem is the following.. I've tried to create a couple of string
class/functions.. and they do compile.. but when I run them.. windows
suddenly reports an error.. As I'm just a beginner in C++, with noone
around me to help.. I'd appreciate if someone might help me out!
The simple (reduced) code is the following:
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h> // for EXIT_SUCCESS
#include <string.h>
class string{
public:
string(void){characters = 0; pt = NULL;}
string(char *s);
private:
int characters;
char *pt;
};
string::string(char *s){
characters = strlen(s);
pt = new char[characters];
if (pt = NULL){
cerr << "Failed to allocate string.\n";
exit(EXIT_FAILURE);
}
memcpy(pt, s, characters);
}
void main()
{
string s1("My first string");
}
If you compile it, you'll see that the compiler doesn't report any
error.. but when running it, you'll see that you suddenly get a
windows error report..
Does someone know what the source of this fault might be and what to
change about the code above?
Thanks!!
- Next message: Gary Labowitz: "Re: please help (novice)"
- Previous message: Michael Post: "Re: ftp-connection under dos6.2"
- Next in thread: Gary Labowitz: "Re: please help (novice)"
- Reply: Gary Labowitz: "Re: please help (novice)"
- Reply: Dirk Feytons: "Re: please help (novice)"
- Reply: Alf P. Steinbach: "Re: please help (novice)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|