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 6722847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:29:49+00:00 2026-05-26T09:29:49+00:00

To me it seems like it should be so simple, but I just feel

  • 0

To me it seems like it should be so simple, but I just feel like I’m missing something.

I have in my header file a private variable _stoplist When I declared it in the header file the code looks just like this.

private:
    std::string _stoplist[];

But when later in my function I decide to access this, it segfaults on anything.

_stoplist[_length];
//cout << _length << prints 104 (its a valid int and everything)
_stoplist[0] = "b";

Crashes in the std::string.assign() code with a segfault. I have a gut feeling that I’m missing something obvious here but I haven’t quite found out what yet.

Thanks in advance!

EDIT: Ok, thanks for all the help. For anyone else who may read this, I would recommend to use one of the answers below since that is the smart way to do it. In my case though since I needed to dynamically allocate it without using vector I just used the following code.

private:
    std::string *_stoplist;

and then in my cpp file

_stoplist = new string[_length];

Yeah, turns out that it really was way simple, and I just was over looking that part.

  • 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-26T09:29:49+00:00Added an answer on May 26, 2026 at 9:29 am

    You’re getting an array out of bounds error because _stoplist doesn’t have a size. You should either give it a size, and only access elements within that range, such as:

    private:
        std::string _stoplist[100];
    

    now you should be able to index _stoplist[0] through _stoplist[99]. However a better solution would probably to use std::vector instead, as it’s a lot safer.

    private:
        std::vector< std::string > _stoplist;
    

    Then you can use its member functions such as resize() to grow it to whatever size you need.

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

Sidebar

Related Questions

This seems like it should be something fairly simple, but I just can't seem
This seems like it should be so simple, but apparently it isn't. I have
This seems like it should be really simple to do but I just can't
This seems like it should be very simple but I can't get it to
Seems like this should be simple, but powershell is winning another battle with me.
This seems like it should be really simple, but I'm unable to figure this
This feels like it should be pretty simple, but not much seems to be
This seems like it should be simple but it's driving me up the wall.
Seems like this should be simple enough but for whatever reason I am unable
This seems like it should be simple but I can't work out how to

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.