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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:11:46+00:00 2026-06-07T13:11:46+00:00

#include<iostream> #include<string> using namespace std; int main(void) { struct STRCT { int num; string

  • 0
#include<iostream>
#include<string>
using namespace std;
int main(void) {

    struct STRCT {
        int num;
        string str1,
               arrStr1[],
               str2,
               arrStr2[];
    };

    int a;
    string b[2],
           c[3],
           d,
           e;

    a = 10;

    b[0] = "hello";
    b[1] = "world";

    c[0] = "stack";
    c[1] = "over";
    c[2] = "flow";

    d = "random";
    e = "text";

    //how do i intialize the arrays (arrStr1[] and arrStr2[]) in aStruct along with the rest of items?
    //is it like this?

    //i want aStruct[] to be an array and i want its size to be declared from the start to later be filled with vals

    STRCT aStruct[2];

    //then later in the program i want to assign aStruct[] vals

    aStruct[0] = {a,      //int
                  d,      //string
                  {b},    //string[]
                  e,      //string
                  {c}};   //string[]
}

so basically i want to make a struct array with arrays inside then get the proper vals and then assign the proper vals to the arrays inside the struct array. thank you very much in advance for the help

  • 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-07T13:11:48+00:00Added an answer on June 7, 2026 at 1:11 pm

    In C++ this is illegal

    string arr[2] = {"This","is"};
    string arr1[2];
    
    arr1 = arr;
    

    There is nothing like “copy an entire array into another array”. The array elements must be copied individually.

    Second you cant declare arrays of unknown size

    You can modify your struct declaration by declaring string array of fixed size and do this

    for(int i =0; i< 2; i++)
    {
    
       aStruct[i].num = a;
       aStruct[i].str1= d;
    
       for(int j=0;j<2;j++)
       {
         arrStr1[i] = b[i];
       }
    
       aStruct[i].str2= e;
    
       for(int k=0;k<3;k++)
       {
         arrStr2[i] = c[i];
       }
    }
    

    I suggest instead of string arrStr1[] ,string arrStr2[] , b[2] and c[2] make use of std::vector. That will help you in avoid hard coding the conditions in for loop.

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

Sidebar

Related Questions

#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main(void) {
#include <iostream> #include <string.h> using namespace std; int main() { int e=0; int b=0;
Here's my code so far: #include<iostream> #include<string> #include<fstream> using namespace std; int main() {
//C++ Example #include <iostream> using namespace std; int doHello (std::string&); int main() { std::string
#include <iostream> #include <string> using namespace std; string crash() { } int noCrash() {
#include <iostream> #include <string> #include <fstream> using namespace std ; string strWord( int index
#include<iostream> #include<stdlib.h> #include<string.h> #include<stdio.h> using namespace std; union type{ int a; char b; int
here is code for regular expression matching #include<iostream> #include<stdio.h> #include<string.h> using namespace std; int
#include<iostream> using namespace std; class TCSGraph{ public: void addVertex(int vertex); void display(); TCSGraph(){ head
#include <iostream> #include <string> #include <vector> using namespace std; struct Exmpl{ Exmpl() { cout

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.