The char_traits, copy() method C++ program example
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C++
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)
Other info: none
To do: Using C++ copy() which copies at most a specified number of characters from an indexed position in a source string to a target character array
To show: How to use the C++ copy() to copy at most a specified number of characters from an indexed position in a source string to a target character array
// the char_traits, copy() example
#include <string>
#include <iostream>
using namespace std;
int main(void)
{
char_traits<char>::char_type str1[ ] = "abcd-1234-abcd";
char_traits<char>::char_type str2[ ] = "ABCD-1234";
char_traits<char>::char_type* result1;
cout<<"The source string is: "<<str1<<endl;
cout<<"The destination string is: "<<str2<<endl;
// note: char_traits::copy is deprecated, consider using char_traits::_Copy_s instead.
result1 = char_traits<char>::copy(str1 , str2 , 4); // C4996 - deprecated
cout<<"The result1 = copy(str1 , str2 , 4) is: "<<result1<<endl;
return 0;
}
Output example:
The source string is: abcd-1234-abcd
The destination string is: ABCD-1234
The result1 = copy(str1 , str2 , 4) is: ABCD-1234-abcd
Press any key to continue . . .