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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:58:47+00:00 2026-06-17T21:58:47+00:00

I have a c++ program currently working with a vector that uses a character

  • 0

I have a c++ program currently working with a vector that uses a character and number as its keys. e.g. myvector['A'][1] = line.substr(0,7). But I need it to work as myvector[1][3] = line.substr(0,7) so I can use both keys as numbers.

In my current working code I had this:

std::vector<std::vector<std::string> >myvector;

I thought simply changing the string to integer would work but I get a “Segmentation Fault (core dumped)” or “cannot convert ‘std::basic_string’ to ‘int’ in assignment” error.

std::vector<std::vector<int> >myvector;

I know that error is very vague but I am new to c++ so I do not how to find any other specific command response for an error. I have looked around on the web for a bunch of examples but have sadly not been able to compile any of them. Any assistance would be greatly appreciated; thank you for your time.

If I am somehow using indexes out of my range here is how I am inputting my indexes.

myvector[rn].resize(100);
std::ifstream fin(argv[3]);
std::string line;
int rn = 0;
int rln = 0;
while( getline(fin, line) ) {  
rn = 0;
while(rn < line.length()/7){
  myvector[rn][rln] = line.substr (rn*7,7);
  rn++;
}
rln++;
}

When I output “line.substr (rn*7,7)” the results are exactly as expected I just cannot set this variable into my vector. Also rn ends up being around 10+ and rln ends at 6.

  • 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-06-17T21:58:49+00:00Added an answer on June 17, 2026 at 9:58 pm

    In C++, string is in double quote "test" not in single code 'test', try:

    std::vector<std::vector<std::string> >myvector(3);
    myvector[1].resize(10);
    myvector[1][3] = "test";
    std::cout << myvector[1][3] << std::endl;
    

    Also With std::vector you have no key concept, actually you are calling access operator[].

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

Sidebar

Related Questions

I have a python program that I am currently working on which is working
I currently have a basic chat program in c++ that uses WinSock2.h with UDP.
Say I have a command line C program which is currently executing, and I
We have an app that currently installs itself into 'program files\our app', and it
I am currently working on a project that deals with a vector of objects
I am currently working on a program that requests input for the names and
I am currently working on a C# program where I have the need to
I am currently working on a Javascript program for my company (Leader Technologies) that
I am currently working on a simple line program in java. There will be
I have a couple issues with a math program im currently working on im

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.