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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:32:52+00:00 2026-05-27T14:32:52+00:00

How come when i assign for a point in the matrix it assigns the

  • 0

How come when i assign for a point in the matrix it assigns the value for the whole column?
I am trying to get it to assign only at that point. Currently I am teaching myself the 2nd part of my computer science class so I am playing with this.
My file just assigns the size of the matrix.
IT compiles and no run time errors.
I am using codeblocks. Any better IDEs?

my sample.txt file grabs two numbers for now 3 and 5.
I am trying to understand so I can implement the rest of the file to put values in the correct points in the matrix.

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

int main()
{
   // variable initialition
   string fileName;
   int value;
   int row=0,col=0; //for size of array
   int a[row][col];
   int row2,col2; // for putting values in array

   fileName="sample.txt";
   ifstream input;
   input.open("sample.txt");

   if (!input)
   {
      cout<<"ERROR: BAD FILE";
   }


   input>>row;
   input>>col;
   cout<<" ROW :"<<row<<endl;
   cout<< " COL :"<<col<<endl;


   for (int indexRow=0; indexRow<row; indexRow++)
   {


      for (int indexCol=0; indexCol<col; indexCol++)
      {
         a[indexRow][indexCol]=0;
      }
   }


   a[0][1]=232;

   for (int row2=0; row2<row; row2++)
   {
      for (int col2=0; col2<col; col2++)
      {


         cout<<a[row2][col2]<<" ";
      }

      cout<<endl;
   }




   input.close();

   return 0;
}
  • 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-05-27T14:32:53+00:00Added an answer on May 27, 2026 at 2:32 pm

    Dynamic arrays are not as simple as that in C++. The syntax you used is for creating fixed-size arrays only. In such case, you need to create your 2D arrays with constant, non-zero values, like the following:

    int a[10][10];
    

    Also,

    input>>row;
    input>>col;
    

    … will definitely not resize your array automatically.

    You should avoid using raw arrays anyway, and consider using a vector of vectors for your 2D array:

    std::vector<std::vector<int>> a;
    

    Please have a look at the following question for more alternatives and discussions about dynamic arrays:

    How do I best handle dynamic multi-dimensional arrays in C/C++

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

Sidebar

Related Questions

I am trying to get key-value-observing to work for an NSMutableArray. Below is the
Title pretty much sums this up. How come it's possible that i can assign
Come across what looks at first sight like an MT-issue, but I'm trying to
I come from a CVS background. I'm currently investigating using SVN for a project.
I am working with the tree data structure and trying to come up with
Readed bog of Ulrich Drepper and come across 2 entries that looks like conficting.
I am trying to assign some javascript variables in a Django template. I am
I'm trying to write a piece of code that will do the following: Take
I've come across a routine that does something like this: static public Bitmap byte2bmp(byte[]
I was wondering whether it is possible to assign a value to an HTML

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.