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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:57:52+00:00 2026-06-09T07:57:52+00:00

I have a really basic problem in c++, I’m reading a tab separated file

  • 0

I have a really basic problem in c++, I’m reading a tab separated file and I want to declare an array with the dimension if the number of fields the file has (work with different files with different widths) so I need to read the first line and count the number of fields, I tried this:

while(getline(t, line));{
...
if(!flag)
{int array[size][5];
flag=1}
...
}

But then I get the error:

error: ‘array’ was not declared in this scope

I understand it is because the scope of the variable is in the if loop, is there any way to declare a null array and resize it? Or will I have to use pointers?

  • 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-09T07:57:54+00:00Added an answer on June 9, 2026 at 7:57 am

    The size of an array must be a compile-time constant. Use a std::vector if you want a dynamically-sized array.

    Other issues with your code:

    1. Remove the semicolon after the while, or your loop body will only be executed once after the whole file is read.

    2. Add a semicolon after flag=1.

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

Sidebar

Related Questions

i have a really basic java program just one .java/.class file (.java uncompiled .class
I have a problem with compiling a basic and really simple example of PyGTK
Hi I have a really basic problem but I couldn't find a tutorial that
i have problems with a really basic thing. setting properties after instantiation a UIViewController-
I have really basic question. How can I get form id by input element
I have a really basic question concerning unix timestamp and mysql date. I'm trying
Alright, I have a really basic QStandardItemModel , filled with some numbers. I managed
Although I know the basic concepts of binary representation, I have never really written
I realize this question is pretty basic, but I'm really stuck. I have a
I have a seemingly basic problem with C# arrays. I am a beginner, but

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.