1

Looking at the following code:

string str = "xxxaa  bbcc";

int pos1 = str.find("a  b"); // pos1=4
int pos2 = str.find('a  b'); // pos2=7
int pos3 = str.find('a  bb'); // error C2015: too many characters in constant
  • Why doesn't the second 'a b' trigger any errors? It always seems to me that '' can only hold one char, but OK for 4 ones here? And why will I get pos2=7 (just like only the last one char 'b' is passed in)?

  • From the second one, it seems '' can hold for multiple chars, why won't it be ok for more than 5 chars, see the third example?

herohuyongtao
  • 49,413
  • 29
  • 133
  • 174

0 Answers0