Thread: Reading values into an array

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688

    Reading values into an array

    Hey guys

    I am getting an error that says:

    \main.cpp no match for 'operator>>' in 'std::cin >> *((+(((unsigned int)i) * 80u)) + brd)'
    All I am trying to do is read the elements into the 2d array. Is it saying I cannot
    use cin to do this?

    The below is the part of my proram which is the only part that has the error.
    I have marked the erorr line.

    Code:
    void move ( const int brd[][ 20 ] )
    {
       int i, j;
       int rowValue;
       int colValue;
    
       std::cout << "Enter number of rows to move: ";
       std::cin >> rowValue;
       std::cout << "Enter nmmber of columns to move: ";
       std::cin >> colValue;
    
       for ( i = 0; i < rowValue; i++ )
       {
          for ( j = 0; j < colValue; j++ )
             std::cout << "Enter value at position [ " << i << "][ " << j << "]: ";
             std::cin >> brd[ i ][ j ];  // ERROR IS HERE
       }
    }
    Double Helix STL

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    You need an opening bracket and an ending bracket for multi-line for loops.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I think the main problem is that you are trying to read into a const int. Try removing the const qualifier first, though I am not sure why the error message reads that way.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Code:
    void move ( const int brd[][ 20 ] )
    You're assigning values to an array that's declared const?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Thanks.

    The "const" was the reason. Technically I had made the array 'read only' hence the error. I anyone wants to know the IDE I use is WxDevC++ 6.10.2

    I could not work out the error, as the usually mean i have used >> and not <<
    Double Helix STL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  2. Reading a list of ints from file into an array
    By mesmer in forum C Programming
    Replies: 1
    Last Post: 11-10-2008, 06:45 AM
  3. copying values of an array to another array?!
    By webznz in forum C Programming
    Replies: 8
    Last Post: 10-24-2007, 10:59 AM
  4. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 09:51 AM
  5. problem: reading user input into an array
    By alpha561 in forum C Programming
    Replies: 13
    Last Post: 05-24-2002, 07:23 PM