string copy in c++ code example
Example 1: copy array in java
int[] src = new int[]{1,2,3,4,5};
int[] dest = new int[5];
System.arraycopy( src, 0, dest, 0, src.length );
Example 2: erasing a character from a string in c++
// string::erase
int main ()
{
std::string str ("This is an example sentence.");
std::cout << str << '\n';
// "This is an example sentence."
str.erase (10,8); // ^^^^^^^^
std::cout << str << '\n';
// "This is an sentence."
str.erase (str.begin()+9); // ^
std::cout << str << '\n';
// "This is a sentence."
str.erase (str.begin()+5, str.end()-9); // ^^^^^
std::cout << str << '\n';
// "This sentence."
return 0;
}
Example 3: string copy in cpp
//use '=' to copy string
string s1={"Hello"};
string s2;
s2=s1; //now s2 will have a copu s1
Example 4: find in string c++
size_t find (const string& str, size_t pos = 0) const;