Problem with cin to char*
Hi, I wanted to pass an input to a char* then pass it to a class member.
but before i even get to the class member, i got stuck in the char* itself.
Code:
#include <iostream>
using namespace::std;
class CTest
{
public:
char *name;
};
CTest Test;
char *gName = "";
int main()
{
cout<<"Enter Name: ";
cin>>gName; //<--here's the error
Test.name = gName;
return 0;
}
after i compile, it's ok.
but once i run it.
then it breaks and popup a message saying:
Quote:
Unhandled exception at 0x104f01be (msvcp80d.dll) in test.exe: 0xC0000005: Access violation writing location 0x0041664b.
then opens a page on the "istream" file.
any leads to solve this?
I thought char* was able to store as string?