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

  • Home
  • SEARCH
  • 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 3441814
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:35:56+00:00 2026-05-18T08:35:56+00:00

header.h #include <iostream> #include <vector> class CombatLine{ std::stringstream Line; std::vector<std::string> TokenLine; void SetLine(std::string s){

  • 0

header.h

#include <iostream>
#include <vector>

class CombatLine{   
    std::stringstream Line;    
    std::vector<std::string> TokenLine;  
    void SetLine(std::string s){   
        Line<<s;   
    }    
public:   
void SetTokenLine(){   
    int i=0;    
    while(i<5){   
        Line>>TokenLine[i];   
        i++;}      
    TokenLine.resize(i);   
    for(int j=0;j<5;j++)   
        cout<<TokenLine[j];} 

main.cpp

#include "Header.h"
using namespace std;   

int main () {   
    CombatLine Line1;   
    Line1.SetLine("[Combat] A bird attacks -Anthrax- and misses (dodge).");   
    Line1.SetTokenLine();   
}   

This builds but I get this runtime error, /cygdrive/C/Program Files/NetBeans 6.9.1/ide/bin/nativeexecution/dorun.sh: line 33: 4500 Segmentation fault <core dumped> sh "$<SHFILE>"

I know it has to do with how I am manipulating strings & streams in the SetTokenFile, but I can’t seem to pinpoint what.

This is a small piece to a larger project. Overall I am going to parse a dynamic text file, and later do comparisons on the entire file’s contents.

  • 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-18T08:35:57+00:00Added an answer on May 18, 2026 at 8:35 am

    You cannot write directly into TokenLine[i] since it’s initialized as an empty vector in your CombatLine constructor. You won’t need the resize if you build the vector up as you read each line.

    Try this:

    void SetTokenLine(){   
        int i=0;    
        string nextLine;
        while(i<5){   
            Line>>nextLine;
            TokenLine.push_back(nextLine);
            i++;}      
        for(int j=0;j<5;j++)   
            cout<<TokenLine[j];}
    

    Alternatively, you could preallocate 5 entries in the vector in the default CombatLine constructor, though this is brittle if the number of tokens you want to process changes. With the below, you can write direct from the stringstream into TokenLine[i] if 0 <= i <= 4.

    CombatLine::CombatLine() : TokenLine(5)
    {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found this vector template class implementation, but it doesn't compile on XCode. Header
This program: test_header.hpp #include <boost/signal.hpp> #include <utility> class Sensor; class Recorder : public ::boost::signals::trackable
include 'header.php'; // ... some code header('Location:index.php'); exit; The above code keeps giving me
I have to include many header files, which are in different sub-directories. Is there
I am getting C++ Compiler error C2371 when I include a header file that
I'm trying to create proper header files which don't include too many other files
I have a C++ program representing a TCP header as a struct: #include stdafx.h
Suppose a header file defines a function template. Now suppose two implementation files #include
I have a couple of header files, which boil down to: tree.h: #include element.h
i have shared the header file containing class definition of a Context Free grammar

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.