cstring header file

This is a discussion on cstring header file within the C++ Programming forums, part of the General Programming Boards category; Hello, I was writing a code with strlen and strcpy functions, and I realized that I forgot to include <cstring> ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    5

    cstring header file

    Hello,

    I was writing a code with strlen and strcpy functions, and I realized that I forgot to include <cstring> header file. But the program run without any problem. My program included <iostream> header file and I am wondering if <iostream> contains <cstring> header file.

    I tried the following code:

    Code:
    //#include <iostream>
    int main()
    {
        char arr[5];
        std::strcpy(arr, "Hey");
        return 0;
    }
    When I omit first line, the compiler gives an error saying strcpy is not a member of std, but when I include the first line, it runs fine.

    Thanks.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,639
    I am wondering if <iostream> contains <cstring> header file
    Possibly, but you should not depend on that, as it may vary from compiler to compiler. Just #include <cstring> yourself.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    5
    Oh, Ok. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  3. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21