Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Error reading characters of string

Error reading characters of string

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
11 Posts 5 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Django_Untaken

    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 = "";

    }

    Richard Andrew x64R Offline
    Richard Andrew x64R Offline
    Richard Andrew x64
    wrote on last edited by
    #2

    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.

    D 1 Reply Last reply
    0
    • Richard Andrew x64R Richard Andrew x64

      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.

      D Offline
      D Offline
      Django_Untaken
      wrote on last edited by
      #3

      I changed that to L"" but in vein. Does it have to do anything with project settings ?

      Richard Andrew x64R 1 Reply Last reply
      0
      • D Django_Untaken

        I changed that to L"" but in vein. Does it have to do anything with project settings ?

        Richard Andrew x64R Offline
        Richard Andrew x64R Offline
        Richard Andrew x64
        wrote on last edited by
        #4

        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.

        D 1 Reply Last reply
        0
        • Richard Andrew x64R Richard Andrew x64

          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.

          D Offline
          D Offline
          Django_Untaken
          wrote on last edited by
          #5

          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);
          
          //.............
          

          }

          Richard Andrew x64R A 2 Replies Last reply
          0
          • D Django_Untaken

            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);
            
            //.............
            

            }

            Richard Andrew x64R Offline
            Richard Andrew x64R Offline
            Richard Andrew x64
            wrote on last edited by
            #6

            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.

            1 Reply Last reply
            0
            • D Django_Untaken

              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 = "";

              }

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #7

              Django_Untaken wrote:

              Here I am getting the said exception

              What exception?

              D 1 Reply Last reply
              0
              • D Django_Untaken

                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);
                
                //.............
                

                }

                A Offline
                A Offline
                Albert Holguin
                wrote on last edited by
                #8

                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() {}
                }

                1 Reply Last reply
                0
                • L Lost User

                  Django_Untaken wrote:

                  Here I am getting the said exception

                  What exception?

                  D Offline
                  D Offline
                  Django_Untaken
                  wrote on last edited by
                  #9

                  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.

                  L S 2 Replies Last reply
                  0
                  • D Django_Untaken

                    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.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #10

                    That suggests that you have not initialised the object. Have you checked that the constructor is called and sets all the variables correctly?

                    1 Reply Last reply
                    0
                    • D Django_Untaken

                      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.

                      S Offline
                      S Offline
                      SundararamanS
                      wrote on last edited by
                      #11

                      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 ?

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups