Problems with string declarations in C++

This is a discussion on Problems with string declarations in C++ within the C++ Programming forums, part of the General Programming Boards category; Hello I have a problem with stings... i can't declare it. For example, this code: Code: #include <iostream.h> #include <string.h> ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    9

    Problems with string declarations in C++

    Hello
    I have a problem with stings... i can't declare it.
    For example, this code:
    Code:
    #include <iostream.h>
    #include <string.h>
    
    int main()
    {
      string s;
      return 0;
    }
    will generate an error:
    Undefined symbol 'string'

    What do i have to do to use strings? I am sorry for this question, but i am kind of new to c++.

    Thanks
    Last edited by Ken Fitlike; 08-09-2006 at 05:12 AM. Reason: inserted code tags

  2. #2
    Registered User
    Join Date
    Aug 2006
    Posts
    12
    I think you should try this:

    Code:
    #include <iostream>
    #include <string>
    
    int main()
    {
        std::string s;
        return 0;
    }
    So include newer header files with no ".h" and use the right namespace. Alternatively put "using namespace std;" after #includes if you like to avoid "std::".

    I hope it helps.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    9
    Thanks for help.
    But now it says:
    Unable to open include file 'IOSTREAM'
    Unable to open include file 'STRING'
    Type qualifier 'std' must be a struct or class name.

    If i write
    using namespace std;

    it says Declaration syntax error.

    What is the problem?

  4. #4
    Registered User
    Join Date
    Aug 2006
    Posts
    12
    The proposed solution seems to work in case of particular compilers, like Visual Studio. I think you should specify which kind of compiler you are using.

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    What compiler are you using? if your compiler doesn't recognise namespaces, then you need to download a new compiler which conforms to the latest version of the C++ standard. (There are plenty of excellent free compilers available - see the FAQ for details)

    incidentally, <iostream> and <string> are case-sensitive, so make sure you type them in lowercase letters.

  6. #6
    Registered User
    Join Date
    Aug 2006
    Posts
    9
    I use Borland C++ version 3.1. I have never thought that i should change the compiler. Where can i get a new one?
    Thanks

  7. #7
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    You sure. That shouldn't happen!

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
        string s;
        return 0;
    }
    try copying that and see if it still errs

  8. #8
    Registered User
    Join Date
    Aug 2006
    Posts
    12
    I think STL and namespaces are not supported by Borland C++ 3.1.

    Maybe you should try other compiler? For instance you can try Visual Studio 2005 from http://msdn.microsoft.com/vstudio/ex...d/default.aspx. Dev-C++ is another choice: http://www.bloodshed.net/devcpp.html.

  9. #9
    Registered User
    Join Date
    Aug 2006
    Posts
    9
    It's not working. It says 'Declaration syntax error' and it points to 'using namespace std''

  10. #10
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,510
    According to Wikipedia, Turbo C++ 3.1 was launched shortly after Windows 3.1 first hit the road. You are using an antique compiler, qmadd.

    You may want to change it. Popular free choices for windows are:

    MinGW
    Visual C++ 2005 Express Edition
    Digital Mars C++
    Comeau C++

    These are probably by order. If you go with MinGW you may want to download either Bloodshed Dev-C++ or Code::Blocks. These are popular choice free IDEs that can be downloaded with the MingW compiler and GDB debugger for ease of installation.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 06:52 PM
  3. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  4. io stream and string class problems
    By quizteamer in forum C++ Programming
    Replies: 2
    Last Post: 04-25-2005, 12:07 AM
  5. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 09:33 PM

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