Error reading characters of string
-
Hello there. I have this structure in Header1.h and instantiating this structure in Header2.h. When I try to initialize this instance, I get this runtime exception. Here is my skeleton of code
HEADER1.h
struct Student {
CString Name;
CString Address;
CString Phone;
};HEADER2.h
class CHeader2Dlg {
//.....
Student student;
//.....
}HEADER2.cpp
void CHeader2Dlg::SomeFunction()
{
student.Name = ""; // Here I am getting the said exception
student.Address = "";
student.Phone = "";}
-
Hello there. I have this structure in Header1.h and instantiating this structure in Header2.h. When I try to initialize this instance, I get this runtime exception. Here is my skeleton of code
HEADER1.h
struct Student {
CString Name;
CString Address;
CString Phone;
};HEADER2.h
class CHeader2Dlg {
//.....
Student student;
//.....
}HEADER2.cpp
void CHeader2Dlg::SomeFunction()
{
student.Name = ""; // Here I am getting the said exception
student.Address = "";
student.Phone = "";}
Are you perhaps using the Unicode character set but assigning an ascii string? Maybe it should be:
student.Name = L"";
The difficult we do right away... ...the impossible takes slightly longer.
-
Are you perhaps using the Unicode character set but assigning an ascii string? Maybe it should be:
student.Name = L"";
The difficult we do right away... ...the impossible takes slightly longer.
I changed that to
L""
but in vein. Does it have to do anything with project settings ? -
I changed that to
L""
but in vein. Does it have to do anything with project settings ?I suspect there is something more going on than just the code you have posted. It sounds as if the CString object is not being instantiated. Maybe if you could post more, relevant code.
The difficult we do right away... ...the impossible takes slightly longer.
-
I suspect there is something more going on than just the code you have posted. It sounds as if the CString object is not being instantiated. Maybe if you could post more, relevant code.
The difficult we do right away... ...the impossible takes slightly longer.
Header1.h
struct Account {
CString Name;
CString Address;
CString Phone;
};Header2.h
class AccountDlg : public CDialog
{
////........
Account account;
////........
}Header2.cpp
void AccountDlg::Load(int id)
{
CEdit* edit;
CComboBox *combobox;account.Name= "asd"; /// EXCEPTION here account.Address= "asd"; account.Phone = "asd"; accountId = id; accountSettings.AccountLoad(accountId,account); //.............
}
-
Header1.h
struct Account {
CString Name;
CString Address;
CString Phone;
};Header2.h
class AccountDlg : public CDialog
{
////........
Account account;
////........
}Header2.cpp
void AccountDlg::Load(int id)
{
CEdit* edit;
CComboBox *combobox;account.Name= "asd"; /// EXCEPTION here account.Address= "asd"; account.Phone = "asd"; accountId = id; accountSettings.AccountLoad(accountId,account); //.............
}
That doesn't reveal anything more than the first post. I think you should post the actual code, not an obfuscated version of it. Show the "#includes" as well.
The difficult we do right away... ...the impossible takes slightly longer.
-
Hello there. I have this structure in Header1.h and instantiating this structure in Header2.h. When I try to initialize this instance, I get this runtime exception. Here is my skeleton of code
HEADER1.h
struct Student {
CString Name;
CString Address;
CString Phone;
};HEADER2.h
class CHeader2Dlg {
//.....
Student student;
//.....
}HEADER2.cpp
void CHeader2Dlg::SomeFunction()
{
student.Name = ""; // Here I am getting the said exception
student.Address = "";
student.Phone = "";}
-
Header1.h
struct Account {
CString Name;
CString Address;
CString Phone;
};Header2.h
class AccountDlg : public CDialog
{
////........
Account account;
////........
}Header2.cpp
void AccountDlg::Load(int id)
{
CEdit* edit;
CComboBox *combobox;account.Name= "asd"; /// EXCEPTION here account.Address= "asd"; account.Phone = "asd"; accountId = id; accountSettings.AccountLoad(accountId,account); //.............
}
Have you tried explicitly calling the struct's constructors in the class constructor?
class AccountDlg: public CDialog
{
Account account;public:
//try explicitly initializing the account structure
AccountDlg() : account() {}
} -
Access violation reading location. Just before this exception, if I debug the application, I see that member variables of this object dont show and
Error reading characters of string
shows up instead, in the intellisense. -
Access violation reading location. Just before this exception, if I debug the application, I see that member variables of this object dont show and
Error reading characters of string
shows up instead, in the intellisense. -
Access violation reading location. Just before this exception, if I debug the application, I see that member variables of this object dont show and
Error reading characters of string
shows up instead, in the intellisense.It does not look like you are reading the string, you are actually assigning values. It seems the exception is from somewhere else.. Is this the complete code you are debugging ?? Could you please share the full code if possible ?