string.h

This is a discussion on string.h within the C++ Programming forums, part of the General Programming Boards category; im trying to use this very simple code, but both VC++6.0 and DevC++4.0 have problems to identify the string....!!! im ...

  1. #1
    looking for the truth moemen ahmed's Avatar
    Join Date
    Feb 2002
    Location
    Egypt
    Posts
    161

    Question string.h

    im trying to use this very simple code, but both VC++6.0 and DevC++4.0 have problems to identify the string....!!!
    im wondering why?

    Code:
    #include <stdio.h>
    #include <iostream.h>
    #include <string.h>
    int main(int argc, char *argv[])
    {
    
      std::cout<<"yess";
      std::cout<<"helloo"<<200;
      int a;
      std::cin>>a;
      std::string s="moemen ahmed";
      string ss=s.substr(7,5);
      cout<<ss;
      cin>>a;
    
      return 0;
    }

    thanks in advance
    Programming is a high logical enjoyable art for both programer and user !!

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>have problems to identify the string
    Can you expand on what your problem is..
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    looking for the truth moemen ahmed's Avatar
    Join Date
    Feb 2002
    Location
    Egypt
    Posts
    161
    my problem was that the compiler had error due to the "string datatype"

    now i got it, it was a very small thing

    #include <string> // the right phrase
    not
    #include <string.h> //the wrong one

    !!!!
    Programming is a high logical enjoyable art for both programer and user !!

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    I believe you need to to std::string to be standard compliant. some compilers need the std::

  5. #5
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330

    ~

    Code:
    #include <cstdio>
    #include <iostream>
    #include <string>
    
    int main (int argc, char *argv[])
    {
    
      std::cout<<"yess";
      std::cout<<"helloo"<<200;
      int a;
      std::cin>>a;
      std::string s="moemen ahmed";
      std::string ss=s.substr(7,5);
      std::cout<<ss;
      std::cin>>a;
    
      return 0;
    }
    The .h tells the compiler, include the C library. <string> and <string.h> are very different things.
    "He who makes a beast of himself, gets rid of the pain of being a man." Dr. Johnson

  6. #6
    looking for the truth moemen ahmed's Avatar
    Join Date
    Feb 2002
    Location
    Egypt
    Posts
    161
    may u tell us more about the differences between both

    thanks
    Programming is a high logical enjoyable art for both programer and user !!

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by moemen ahmed
    may u tell us more about the differences between both

    thanks
    <string> is the C++ version, giving you these

    <string.h> is the C version, giving you these
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Understanding strtok from string.h library
    By yougene in forum C Programming
    Replies: 6
    Last Post: 03-07-2008, 01:14 AM
  2. Where is strcpy() defined? (Can't find in string.h ect)
    By Zero_Point in forum C++ Programming
    Replies: 6
    Last Post: 04-03-2006, 06:14 PM
  3. censor text without string.h & afx.h
    By slimshady783 in forum C++ Programming
    Replies: 1
    Last Post: 02-09-2003, 10:58 PM
  4. string.h help
    By gcnmetroid in forum C++ Programming
    Replies: 2
    Last Post: 04-30-2002, 12:29 AM
  5. string.h functions help plz :)
    By ChrisE in forum C++ Programming
    Replies: 1
    Last Post: 03-05-2002, 03:12 PM

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