dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Cannot modify values through vector itertor

  1. #1
    Join Date
    Oct 2006
    Posts
    144

    Cannot modify values through vector itertor

    Hello ALL,

    I have a vector

    vector<CLUSTER> ClustList; where


    Code:
    struct CLUSTER{
        string DocID_DocName;
    }
    some members of CLUSTER have been ignored for simplicity
    Initially, I put 3 elements into ClusterList by using push_back()
    the content in DocID_DocName is shown below.

    Code:
    ClusterList[0].DocID_DocName = "0";
    ClusterList[1].DocID_DocName = "1";
    ClusterList[2].DocID_DocName = "2";
    In the following program snippet, I want to update the content of ClusterList[0].DocID_DocName, ClusterList[1].DocID_DocName and ClusterList[2].DocID_DocName
    with iterator


    Code:
    vector<CLUSTER>::iterator it;
    for(it = ClusterList.begin(); it != ClusterList.end(); it++)
    {
         // do mapping, so that I get DocName according to DocID
         // DocID    DocName
         //  0            NewsTilte.txt
         //  1            NewsProvider.txt
         // 2             NewsUser.txt
        String Str //mapping result is stored into Str
        (*it).DocID_DocName = Str;// cause segment fault.
    }
    The statement
    (*it).DocID_DocName = Str;
    caused segment fault.

    The length of Str is longer than that of the origianl content.

    But, I still cannot figure out the reason.
    Please help. Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,768

    Re: Cannot modify values through vector itertor

    Post the smallest and simplest compilable program that demonstrates the segmentation fault.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Cannot modify values through vector itertor

    Code:
        String Str //mapping result is stored into Str
        (*it).DocID_DocName = Str;// cause segment fault.
    This code cannot compile. Post the actual code.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)