1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

G++ Compiler Isuue

Discussion in 'C++' started by obscurecoder, Jun 18, 2010.

  1. obscurecoder

    obscurecoder New Member

    Joined:
    Jun 7, 2010
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    I'm using G++ compiler version 4.4.1. I tried to compile my program and it shows the following errors:

    [NOPARSE]
    SequenceOfCommands.cpp: In function ‘int main()’:
    SequenceOfCommands.cpp:75: error: no match for ‘operator>>’ in ‘std::cin >> s’
    /usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/istream:119: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::eek:perator>>(std::basic_istream<_CharT, _Traits>& (*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/istream:123: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::eek:perator>>(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/istream:130: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::eek:perator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/istream:166: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::eek:perator>>(bool&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/istream:170: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::eek:perator>>(short int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/istream:173: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::eek:perator>>(short unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/istream:177: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::eek:perator>>(int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/istream:180: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::eek:perator>>(unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/istream:184: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::eek:perator>>(long int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/istream:188: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::eek:perator>>(long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/istream:193: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::eek:perator>>(long long int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/istream:197: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::eek:perator>>(long long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/istream:202: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::eek:perator>>(float&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/istream:206: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::eek:perator>>(double&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/istream:210: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::eek:perator>>(long double&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/istream:214: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::eek:perator>>(void*&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/istream:238: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::eek:perator>>(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>]
    SequenceOfCommands.cpp:76: error: no matching function for call to ‘SequenceOfCommands::whatHappens(std::string [51])’
    SequenceOfCommands.cpp:16: note: candidates are: std::string SequenceOfCommands::whatHappens(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >)
    [/NOPARSE]
    As far as I know, my program should at least compile. My program is as follows:
    Code:
    #include<iostream>
    #include<cstring>
    #include<cmath>
    #include<cstdlib>
    #include <vector>
    #define NORTH 1
    #define EAST 2
    #define SOUTH 3
    #define WEST 4
    using namespace std;
    
    class SequenceOfCommands{
    public:
    string whatHappens(vector <string> com)
    {
    int dir = NORTH;
    int vis[2510][2510] = {false};
    int x, y, flag = false;
    x = y = 1255;
    vis[x][y] = true;
    for(int loop=0; loop<100; loop++)
    {
    for(int i=0; i<com.size(); i++)
        {
    //    string s = com[i];
        for(int j=0; j<com[i].length(); j++)
            {
            if(com[i][j]=='R')
                {
                switch(dir)
                {
                case NORTH: dir = EAST; break;
                case SOUTH: dir = WEST; break;
                case EAST: dir = SOUTH; break;
                case WEST: dir = NORTH; break;
                }
                }
            else if(com[i][j]=='L')
                {
                switch(dir)
                {
                case NORTH: dir = WEST; break;
                case SOUTH: dir = EAST; break;
                case EAST: dir = NORTH; break;
                case WEST: dir = SOUTH; break;
                }
                }
            if(com[i][j] == 'S')
                {
                switch(dir)
                {
                case NORTH: y++; break;
                case SOUTH: y--; break;
                case EAST: x++; break;
                case WEST: x--; break;
                }
                }
            if(!vis[x][y]) vis[x][y] = true;
            else continue;
            }// for j ends
        }//for i ends
    if(x == 1255 && y == 1255) {flag = true; break;}
    }//for loop ends
    if(flag) return "bounded";
    return "unbounded";
    }
    };
    
    int main()
    {
    SequenceOfCommands var;
    string s[51], ans;
    cin>>s;
    ans = var.whatHappens(s);
    cout<<ans<<endl;
    return 0;
    }
     
    Last edited by a moderator: Jun 18, 2010
  2. obscurecoder

    obscurecoder New Member

    Joined:
    Jun 7, 2010
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Sorry about the smileys, they're because of some character translation, but I think the errors are still clear.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    Smiley issue taken care and also you should post code inside the code block for formatting.
     
  4. obscurecoder

    obscurecoder New Member

    Joined:
    Jun 7, 2010
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Oh, sorry, thanks. But can you tell me how can I remove this error? The code's fine as far as I know...
     
  5. jimblumberg

    jimblumberg New Member

    Joined:
    May 30, 2010
    Messages:
    120
    Likes Received:
    29
    Trophy Points:
    0
    In the following snippet:
    Code:
       string s[51], ans; 
       cin>>s;
    
    string s[51]; //defines an array of 51 strings
    cin >> s; // use a single string (no array subscript)

    You should drop the array since you are not using arrays anywhere in your code.
    Code:
       string s;
       cin >> s;
    
    Jim
     
    shabbir likes this.

Share This Page