asceD's blog

By asceD, history, 4 weeks ago, In English,

Here are two submission — Accepted_one || Compilation_error_one. I don't understand why strstr is behaving different in those two solutions?

 
 
 
 
  • Vote: I like it  
  • -3
  • Vote: I do not like it  

»
4 weeks ago, # |
  Vote: I like it +15 Vote: I do not like it

strstr doesn't work with C++ strings. This has nothing to do with bits/stdc++.h.

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it -11 Vote: I do not like it

    then why did it work in the first submission??

    • »
      »
      »
      4 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Because you didn't used any C++ style strings. Only C style strings, aka char arrays.

    • »
      »
      »
      4 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      It's because a C++ string is not equivalent to a character array (C style String). Your code works fine when using a char array instead 40550976.It gives a error as compiler cannot implicitly covert c++ string into a char array. To construct C string out of a string c_str method is used. Difference bw c and c++ style string .