Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   G++ Compiler Isuue (http://www.go4expert.com/forums/g-compiler-isuue-t22473/)

obscurecoder 18Jun2010 15:13

G++ Compiler Isuue
 
I'm using G++ compiler version 4.4.1. I tried to compile my program and it shows the following errors:


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>::operator>>(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>::operator>>(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>::operator>>(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>::operator>>(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>::operator>>(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>::operator>>(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>::operator>>(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>::operator>>(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>::operator>>(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>::operator>>(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>::operator>>(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>::operator>>(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>::operator>>(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>::operator>>(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>::operator>>(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>::operator>>(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>::operator>>(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::b asic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >)

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;
}


obscurecoder 18Jun2010 15:15

Re: G++ Compiler Isuue
 
Sorry about the smileys, they're because of some character translation, but I think the errors are still clear.

shabbir 18Jun2010 15:32

Re: G++ Compiler Isuue
 
Smiley issue taken care and also you should post code inside the code block for formatting.

obscurecoder 18Jun2010 16:05

Re: G++ Compiler Isuue
 
Oh, sorry, thanks. But can you tell me how can I remove this error? The code's fine as far as I know...

jimblumberg 18Jun2010 17:58

Re: G++ Compiler Isuue
 
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


All times are GMT +5.5. The time now is 03:15.