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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:51:58+00:00 2026-06-15T06:51:58+00:00

Sorry beginner here. I’m trying to get the string size from the cin function,

  • 0

Sorry beginner here. I’m trying to get the string size from the cin function, then use that to declare array size. But it’s saying:

line 17: request for member ‘size’ in ‘x’, which is non-class type ‘std::string long int’.

It works fine without the array though.

#include <iostream>
#include <string>
using namespace std;

int main()
{
    int y;
    string x[y];
    cout << "Enter sequence" << endl;
    cin >> x[y];
    y = x.size;

    for (int i = 0; i > y; i++)
        cout x[i];

    cout << "The size of the sequence is " << x.size() << " characters." << endl;
}
  • 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-15T06:51:59+00:00Added an answer on June 15, 2026 at 6:51 am

    First, of all declaring an array as you do is not allowed. Let’s take a look at these two lines of code

    int y;
    string x[y];
    

    In the second line of code, what is the value of y? It could be anything. Certainly the compiler doesn’t know, and the array size must be determined at compile-time.

    There are two solutions to your problem:

    1. Use pointers and dynamically allocate an array.

    2. Use std::vector and let the standard library take care of the dynamic allocation.

    IMO, both are tools which you should have in your programmer tool belt, so you should learn how to do both. You should also learn the advantages and disadvantages of either approach so that you can choose the correct one to solve a problem.

    Finally, the error message that you get means that an array does not have a member called size(). If you fix this using solution 1. above, you will need to keep track of the size yourself.

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

Sidebar

Related Questions

Sorry, beginner here . . . So I create an NSMutableDictionary in my app
Sorry in advance for this being such a beginner question. Here are the steps
Sorry i'm a beginner,from what i know there are number of varieties of libraries
Sorry for this extreme beginner question. I have a string variable originaltext containing some
first,sorry for my bad English!! i'm new here and i'm a beginner of android
Sorry, a beginner's question: I have a very simple function in my Django application
Sorry I'm beginner, can somebody help me out? <script> var iW = $(document).width(); $(function()
Ok guys, i'm very beginner and trying to enter string to a char array
Firstly sorry, I'm a really big beginner. I ran into a problem that I
I'm not a complete beginner and sorry for posting an ambiguous question that has

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.