LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   error: no match for operator (https://www.linuxquestions.org/questions/programming-9/error-no-match-for-operator-907288/)

hollyj 10-09-2011 04:43 PM

error: no match for operator
 
Hey guys! I'm an extremely new c++ programmer. Can you offer suggestions on why I get the "no match for operator" error with the following code? I think it may be that my text file is too big for a string.

#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<fstream>
#include<stdlib.h>



using namespace std;



int main(){

string line;
ifstream text( "text.txt" );
getline( text, line );
text.close();
//for( int i = 0; i < line.length(); i++ ){
// cout << line[ i ] << " ";
//}
cout << endl;

string P = "is";



long long int PRIME = atoll("10002949999");

int l_line = line.length(), l_P = P.length(), t=0, h = 1, d = 26, H = 0;

for (int i=1; i < l_P; i++)

h = (h * d) % PRIME;

for (int i=0;i<l_P;i++) {

H = ( (d*H) + P[i] - 'a')%PRIME ;

t = ( (d*t) + line[i] - 'a')%PRIME ;

}
for (int i = 0, j = l_line - l_P - 1 ; i < j ; i++){

if (t == H){

int state = 1;

for (int k = 0 ;k < l_P; k++)

if (line[i+k] != P[k]){

state = -1;

break;

}

if (state == 1 ){

cout << " Match found at index : " << i << "\n";

}

}

else{

t = ( (d * (t - h*(line[i]-'a')) + line[i+l_P] - 'a')%PRIME );

}

}

return 0;

}

eSelix 10-09-2011 04:49 PM

What this means?
Code:

cin >> "is"
And please use CODE tags around your code, and specify exact error message you get (with line number).

hollyj 10-09-2011 04:50 PM

Well now it doesn't return an error. It returns nothing.

ta0kira 10-09-2011 05:38 PM

Quote:

Originally Posted by hollyj (Post 4494063)
Well now it doesn't return an error. It returns nothing.

Doesn't that mean it compiled, then? You shouldn't edit your post to remove the problems you're asking about because when other people read the post they can't find evidence of the problem. You should also post complete error messages since they include the semantic information necessary to figure out where the problem is.
Kevin Barry


All times are GMT -5. The time now is 04:34 PM.