Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6171717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:15:58+00:00 2026-05-23T23:15:58+00:00

After excellent advice I defined a struct, filled it with data read from a

  • 0

After excellent advice I defined a struct, filled it with data read from a file and pushed it on a vector. Nice!!! Could somebody tell me now how I can call back the content of a member of the i-th struct I pushed on the vector?

The Structure definition:

struct Config_Data
{
    int Surf_Index;
    std::string Surf_Mnemo;
    double Surf_Param[5];
    std::string Surf_Comm;
};

Instantiation of the Struct and the definition of the vector:

Config_Data SURF;
std::vector<Config_Data> CDATA_SURF;

For filling the struct:

for (i=1;i<=10;i++)
{
    getline(INP_Stream, Line, delim_Config);
    SURF.Surf_Index=atoi(Line.c_str());

    getline(INP_Stream,SURF.Surf_Mnemo,delim_Config);
    SURF.Surf_Param[0]=Mnemo_list[SURF.Surf_Mnemo];
    for (j=1;j<=Mnemo_list[SURF.Surf_Mnemo];j++)
    {
        getline(INP_Stream,Line,delim_Config);
        SURF.Surf_Param[j]=strtod(Line.c_str(),NULL);
    }
    getline(INP_Stream, SURF.Surf_Comm,delim_Line);
    CDATA_SURF.push_back(SURF);
    cout<<CDATA_SURF.size()<<endl;
    string aaa=CDATA_SURF[i].Surf_Comm;
}

As you can see I read strings from a csv file. I am not so happy with the way I convert strings in the int or double types, but it seem to work.

The way I wanted to call the i-th struct in the vector and its member Surf_Comm:

std::string aaa=CDATA_SURF[i].Surf_Comm;   

I compiled without problems but at runtime I get segment violation signals. Being a beginner, I have no clue what is going on.

All help is very welcome!!!

Thanks in advance,

Regards,

Stefan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:15:58+00:00Added an answer on May 23, 2026 at 11:15 pm

    Element numeration in std::vector starts with zero value. Thus if vector holds one element, index of this value is 0. In case of two values – 0 and 1 and so on. Do not be confused by the size() vector method. It returns a number of holding elements.

    So index of the newly pushed value equals to size()-1. Access to i-th element (that does not exist) results into an error.

    This code should work if you change range of i value in cycle to for( i = 0; i < 10; i++ ).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Phil Haack has an excellent blog post on how to use JSON, data binding,
Two excellent results of SOLID development ideology are - Legibility - Extensibility over the
I am working through the (excellent) railstutorial.org site have have a basic question about
In my MS Access application I have several forms that are very data intensive
I need a regex for the ASP.Net (4) Regex Validation control. It needs to
So I have case statements grouped together here, but I have a few case
I just recently finished reading Secure Coding in C and C++ by Brian Seacord,
Greetings, I am trying to code a solution for an order form pricing calculator
I'm quite new to Javascript and the GoogleMaps API.. I have a problem with
Ruby (and the Rails framework) is the first new programming language that I've learned

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.