Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance comparison: strstr() vs std::string::find()

Tags:

c++

c

string

Can someone please explain why I should use strstr or string find() ? Which one is faster, at where ?

like image 984
deniz Avatar asked Nov 28 '22 02:11

deniz


2 Answers

In C++ you should use std::string::find(), in C you should use strstr(). The difference in performance should not be significant.

like image 165
Dirk Holsopple Avatar answered Dec 05 '22 11:12

Dirk Holsopple


It doesn't matter which is faster. Much more important is that the std::string::find is safe. So use std::string class and avoid old c functions, if you are going to use c++.

like image 22
AlexTheo Avatar answered Dec 05 '22 09:12

AlexTheo