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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:46:10+00:00 2026-06-17T06:46:10+00:00

I have been trying to create a sample application in Visual Studio 2010. I

  • 0

I have been trying to create a sample application in Visual Studio 2010. I am not getting what is the problem as the code is perfectly compiling, but is giving run-time error. Here is the code:

#include <Map>
#include <string>
#include <sstream>
#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char* argv[])
{
    map <int, string> *sss = new map<int, string>;
    sss->at(0) = "Jan";
    sss->at(1) = "Feb";
    sss->at(2) = "Mar";
    sss->at(3) = "Apr";
    sss->at(4) = "May";
    sss->at(5) = "Jun";
    string current = NULL;
    ofstream myfile;
    myfile.open("daily_work.txt");
    myfile << "*****   DAILY WORK   *****" << endl;

    for(int i = 0; i < 6; i++)
    {
        string month = sss->at(i);
        for(int j = 1; j < 31; j++)
        {
            stringstream ss;
            ss << j;
            current = ss.str();
            current.append(" ");
            current.append(month);
            current.append(" = ");
            myfile << current << endl;
        }

        current = "";
    }

    printf("Completed!");
    myfile.close();
    sss->clear();
    delete sss;
    sss = NULL;
    return 0;
}

The error is thrown at line no 2 in main.

sss->at(0) = "Jan";

Please find the error here:

enter image description here

  • 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-17T06:46:11+00:00Added an answer on June 17, 2026 at 6:46 am

    Method map.at does access at the element 0. You have just created the map, so you element 0 is empty. Use insert and read this documentation about maps.

    c++ reference map

    I suggest you also to avoid for 1 ... 6, iterator is the preferred way to cycle a map.
    In this way, if you add element to your map, you don’t need to to anything else, the loop will automatically adjust itself.

    Use this sample:

    typedef std::map<int, string>::iterator it_type;
    for(it_type iterator = map.begin(); iterator != map.end(); iterator++) {
        // iterator->first = key
        // iterator->second = value
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to create an application to go through our database at
I'm a newbie to Visual Studio (2010) and Expression Studio (4). I have been
I have been trying to create a simple application that will let the user
I have been trying to create a fairly simple application in WPF following the
I have been trying to create a simple program with Python which uses OpenCV
I have been trying to create an XML using the simplexml library (v2.6.2) http://simple.sourceforge.net/home.php
I have been trying to create a ListView which I can sort using drag
I have been trying to create a menu panel with jQuery that can be
I have been trying to create a new google custom search engine, but when
I have been trying to create an observable tweeter feed using tweetsharp with the

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.