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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:03:25+00:00 2026-06-04T02:03:25+00:00

I am new to c++ programming and I have a basic issue, I want

  • 0

I am new to c++ programming and I have a basic issue, I want to create N objects, N is is actually a user input.

I am specific about having object names, say beam1, beam2,…,beamX.

2 quick things

  1. Is it possible in C++ to create dynamic object as this?
  2. if it is how do we do tht? I am pasting code for your refrence..

        #include "iostream"
        # include <conio.h>
        using namespace std;
    
        // Static member variable is defined outside the class..
        class beam {
        public:
        int length;
        };
    
        int main () 
        {
           int i=0, no_of_spans, j;
           cout<< "Design Of a Continous Beam \n1) No Of Spans : ";
           cin >> no_of_spans;
           for (i =0; i < no_of_spans; i++) {
             j = i;
             beam;
             cout << "Length of Beam" << j+1 << " is : ";
             cin >> beami.length;
           }
    
           cout << "\nPress any key to continue..\n";
           getch ();
        }
    

This is obviously a code with errors, its put up as an example to get the idea.

  • 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-04T02:03:26+00:00Added an answer on June 4, 2026 at 2:03 am

    As has already been stated by others (Luchian, John, Component and Ed) you can use a std::vector and it will dynamically grow as necessary to store the number of beam objects required.

    If you wish to refer to these objects later by name you could store them in a std::map, with the key of the map being the object name (e.g. beam1, beam2, beam3, …, beamX):

    std::map<std::string, beam> beams;
    for (int i = 0; i < no_of_spans; i++)
    {
        j = i;
        beam beam;
        std::string beam_name("beam" + boost::lexical_cast<std::string>(i + 1));
        cout << "Length of " << beam_name << " is : ";
        cin >> beam.length;
        beams.insert(std::make_pair(beam_name, beam));
    }
    

    —

    boost::lexical_cast<> is a mechanism for converting (in this case) an int to a std::string. There other ways to achieve this (using std::ostringstream for example).

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

Sidebar

Related Questions

I'm new to PHP programming and have poor knowledge about it, but I want
I am new to Qt Programming, but I have basic on C++. I want
I am new to web programming...I have been asked to create a simple Internet
I am just new to programming in Unix and have a small issue that
I am new to programming. I have lots of interest in networking and want
I am new to VSTO programming. I have created a basic addin for Outlook
I'm fairly new to iOS programming, but have a basic understanding of it. I
I am new to stackoverflow and the programming world. I have a basic program
I’m new to visual basic.net . I have experience in C++ programming, but never
I'm new to programming, I have some basic python programming from college, I am

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.