how would i use
.insert
.erase
.find
on a string. i found references on them, but not how to use them.
Printable View
how would i use
.insert
.erase
.find
on a string. i found references on them, but not how to use them.
Search MSDN, they have examples on these functions.Code:// for convenience:
typedef string::size_type off;
// a string:
string str1("abcdefgh");
// get the offset of the letter d
off o1 = str1.find('d');
// insert some other characters there
str1.insert(o1, "Hello there!");
cout << str1;
// erase the last 3 characters:
str1.erase(str1.end()-3, str1.end());
btw i get
error C2653: 'string' : is not a class or namespace name
Code:#include <string>
using namespace std;
just created more errors,
int __stdcall PStrReplace(char* lpString,char* lpFind,char* lpReplace,string *lpbuffer)
off StringLv = lpbuffer.find('d');
F:\C++\newprojects\Quser32\QUSER32.cpp(27) : error C2228: left of '.find' must have class/struct/union type
Use a reference, not a pointer (i.e. string &buffer). If you're following the Hungarian naming convention then drop the "lp" as well.