aamir.coding's blog

By aamir.coding, 14 years ago, In English
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...
  • Vote: I like it
  • 0
  • Vote: I do not like it

14 years ago, # |
  Vote: I like it 0 Vote: I do not like it
size is a function, you need to call it like this: A.size()
  • 14 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    ok...
    thanks for that...
    But still getting some other compilation error
    • 14 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it
      Then, I suppose, there is some other mistake in your code.
14 years ago, # |
  Vote: I like it 0 Vote: I do not like it
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 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    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 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it
      Btw, your code

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


      compiles okay...

    • 14 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it
      Well, you should use C++ compiler, so command should look like "g++ a.cpp". gcc - is C compiler, while g++ used for C++
14 years ago, # |
  Vote: I like it 0 Vote: I do not like it
Topic not found.