dimanche 1 mars 2015

error : binary '>>' : no operator found which takes a right-hand operand of type 'const char [1] And program crashes after taking first input

This is a simple program which takes 2 numbers ,reverse them and print their reversed sum .But i am facing two problems. 1 . if i keep using "cin >> " it gives error "binary >> :no operator found which take a right hand operand of typr 'const char[1](or there is no acceptable version )" . 2. if i use "scanf_s()" instead of " cin >> " then it crashes after taking first number . This is my code :



enter code here int calculate_sum(string num){
stack<char> mystack;
int sum = 0;
for (int i = 0; i < num.length(); i++){
mystack.push(i);
}
while (!mystack.empty()){
char c; int n;
c = mystack.top();
mystack.pop();
n= (int)c;
sum = sum + n;

}
int main(){
cout << "Enter testcases:" << endl;
int testcase=0;
cin >> testcase;
while (testcase--){
string num1, num2;
int rev_sum1, rev_sum2, final_sum;
int sum = 0;
cin >> num1 >> "" >> num2 ;
//scanf_s("%s %s", num1, num2);
rev_sum1 = calculate_sum(num1);
rev_sum2 = calculate_sum(num2);
final_sum = rev_sum1 + rev_sum2;
cout << final_sum << endl;
}
return sum;


}


Aucun commentaire:

Enregistrer un commentaire