Блог пользователя aamir.coding

Автор aamir.coding, 14 лет назад, По-английски
I have written following program for problem 14 A(Letter):
#include <iostream>
#include <vector>

using namespace std;

typedef vector<int> vi;
int main()
{
int row,col;
char element;
cin>>row>>col;
const int cols=col;
const int rows=row;
char Array[rows][cols];
vi A;
vi B;
for(int i=0;i<row;i++)
{
  for (int j=0;j<col;j++)
   {   cin>>element; Array[i][j]=element;
    if (Array[i][j]=='*')
    {  A.push_back(i);
       B.push_back(j); }
   
   }
}

for(int i=A.at(0);i<A.at(A.size);i++)
{
  for (int j=B.at(0);j<B.at(B.size);j++)
   {   cout<<Array[i][j];
               
   }
}

return 0;
}  


I am getting the following compilation error which i am not able to fix....
can anybody help


Compilation Error:
In function ‘int main()’:
letter.cpp:73: error: no matching function for call to ‘std::vector<int, std::allocator<int> >::at(<unresolved overloaded function type>)’
/usr/include/c++/4.4/bits/stl_vector.h:650: note: candidates are: typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::reference std::vector<_Tp, _Alloc>::at(size_t) [with _Tp = int, _Alloc = std::allocator<int>]
/usr/include/c++/4.4/bits/stl_vector.h:668: note:                 typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::const_reference std::vector<_Tp, _Alloc>::at(size_t) const [with _Tp = int, _Alloc = std::allocator<int>]

letter.cpp:75: error: no matching function for call to ‘std::vector<int, std::allocator<int> >::at(<unresolved overloaded function type>)’
/usr/include/c++/4.4/bits/stl_vector.h:650: note: candidates are: typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::reference std::vector<_Tp, _Alloc>::at(size_t) [with _Tp = int, _Alloc = std::allocator<int>]
/usr/include/c++/4.4/bits/stl_vector.h:668: note:                 typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::const_reference std::vector<_Tp, _Alloc>::at(size_t) const [with _Tp = int, _Alloc = std::allocator<int>]

Thanks in advance...
  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

14 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
А вообще может кто нибудь сказать такое
cin>>row>>col;
const int cols=col;
const int rows=row;
char Array[rows][cols];
вообще реально скомпилировать? Я слышал, что в g++, что то подобное есть. Просто лично для меня кажется гораздо понятней в такой ситуации юзать вектор.
  • 14 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Реально. Я сделал небольшие поправки к коду автора и AC.

    Это называется VLA, оно является частью стандарта C99 (не Си++).

14 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
size is a function, you need to call it like this: A.size()
14 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
I suppose that B.at(B.size()) gives you an element not within array (0-based).
Maybe you need B.at(B.size()-1)?
  • 14 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится
    I have written the following code for testing.....
    It is also not able to compile:
    #include<iostream>
    using namespace std;
    int main()
    {
    cout<<"Testing";
    return 0;
    }

    i am running Ubuntu 10.04....
    Command which i use for compilation is :
    gcc a.cpp

    is there any error..
    please help
                  
    • 14 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится
      Btw, your code

      #include<iostream>
      using namespace std;
      int main()
      {
      cout
      <<"Testing";
      return 0;
      }


      compiles okay...

    • 14 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится
      Well, you should use C++ compiler, so command should look like "g++ a.cpp". gcc - is C compiler, while g++ used for C++
14 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
Topic not found.