convert int to char*

hy, I'm having problems converting int to char*

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <string>
using std::string;

class Classname {
private:
	char* pointer;
public:
        char* getit() {return pointer;}
};
Classname(int num) : pointer(new char[6]) {
	strcpy(pointer,(char*)num);     //Access violation reading location
}
int main(int argc, char* argv []) {
	Classname object(1997);
	cout << obj.getit();
	return 0;
}


I've tryed static_cast and all sort of things -- no success :/

itoa function work well but a task(from my book) say to do that so somehow I dont know lol
Last edited on
Topic archived. No new replies allowed.