CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: string.h

  1. #1
    Join Date
    Nov 1998
    Posts
    20

    string.h

    I have used #include<string.h> and then declared String str1, str2; and have not been able to use cin>>str1; after prompting for input.


  2. #2
    Guest

    Re: string.h

    try using the function: getline (cin, stringname,'\n'); to see what happen.

    dh


  3. #3
    Join Date
    Sep 1999
    Location
    usa
    Posts
    57

    Re: string.h

    use it without capitals.

    #include <string.h>
    string strFile;

    mtighe,

    [email protected]

  4. #4
    Join Date
    Jun 1999
    Location
    Miami, FL
    Posts
    972

    Re: string.h

    You have 3 problems:

    1. The header file is included as <string> (instead of <string.h&gt
    2. The class you need is string (not String).
    3. To use the string class directly, you need to declare the std namespace at the top of the file:

    using namespace std;



    Cheers!
    Alvaro


  5. #5
    Join Date
    Sep 1999
    Location
    NJ
    Posts
    1,299

    Re: string.h

    In reply to:


    3. To use the string class directly, you need to declare the std namespace at the top of the file:
    using namespace std;




    If you're just using one (or even just a few) things from the standard library, it's it's better to insert the individually into the global namespace, instead of dragging the entire library in:

    using std::string;
    using std::cin;

    string Str1, Str2;
    cin >> Str1;



    Sometimes, it's best just to qualify the name where it's used:

    std::string Str1, Str2;
    std::cin >> Str1;




    Truth,
    James

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured