[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CppStrcpy

(C++) std::strcpy

The standard function std::strcpyt copies char*'s (i.e. C-style-strings, or null-terminated strings).

The example below copies a char* over another.

  1. include <cstring>
  2. include <cassert>
int main() { char * const name1 = "Bilderbikkel"; char * const const name2 = "was here...."; //assert(name1=="Bilderbikkel"); //Won't work, only for std::strings assert(std::strcmp(name1,"Bilderbikkel")==0); //Copy name2 over name1 std::strcpy(name1,name2); //assert(name1=="was here...."); //Won't work, only for std::strings assert(std::strcmp(name1,"was here....")==0); }


Use std::string instead of an array of char [1,2].

Code links

'strcpy' links

  •  ?C

Reference



last edited (April 2, 2007) by bilderbikkel, Number of views: 793, Current Rev: 2 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.