+ 5
How to compare string units?
For a string we can use cout<<name.at[4]; to print it on the screen but how can I compare them like string x; cin>>x; x.at[2] == "A";//It shows error pls help
4 Answers
+ 4
wrap A by using single quote rather than double quote
string x;
cin>>x;
x.at(2) == 'A';
+ 4
Thanks Thanks Thanks alot
+ 3
Can you help me with this code pls
https://code.sololearn.com/cp9dy789S7ak/?ref=app
+ 2
#include <iostream>
// Flip The Binary
int main() {
std::string bin; // i change the type to string rather than int
std::cin >> bin;
std::cout << "then: ";
std::cout << bin << std::endl;
for (int x = 0; x < bin.length(); ++x){ // change the <= operator by <
if (bin.at(x) == '0'){
bin.at(x) = '1';
}else if (bin.at(x) == '1'){ // forgot parenthes
bin.at(x) = '0';
}
}
std::cout << "now: ";
std::cout << bin << std::endl;
}