C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28695
Number of posts: 94715

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
string data type Posted by perfectvijay on 13 Apr 2008 at 6:06 AM
hi actually i wanted to use a string data type available in c++. i tried to use it like this

#include<string.h>
....
....
{
string str("ALPHA");
}
it is giving an error and am using turbo 3.0 c++ compiler..
plz help me!!!
Report
Re: string data type Posted by Lundin on 13 Apr 2008 at 6:52 AM
Correct syntax is

#include <string>
using namespace std;

However, that won't work on TC3 since it doesn't follow the C++ standard. I would strongly advise you to get a modern compiler which does.


Report
Re: string data type Posted by perfectvijay on 17 Apr 2008 at 7:34 AM
i did that also but still not working i teied it on bc++ 5 also still not working!!

Report
Re: string data type Posted by Lundin on 17 Apr 2008 at 8:26 AM
Post compiler messages.
Report
Re: string data type Posted by perfectvijay on 20 Apr 2008 at 5:31 AM
i used bc++ 5 but still its not working..

Report
Re: string data type Posted by MT2002 on 21 Apr 2008 at 6:07 PM
: i used bc++ 5 but still its not working..

As Lundin pointed out, you need to post error messages in order for us to help you.

[.:EvolutionEngine][.:MicroOS Operating System][Website :: OS Development Series]
Report
Re: string data type Posted by ColacX on 17 Apr 2008 at 8:10 PM
: hi actually i wanted to use a string data type available in c++. i
: tried to use it like this
:
: #include<string.h>
: ....
: ....
: {
: string str("ALPHA");
: }
: it is giving an error and am using turbo 3.0 c++ compiler..
: plz help me!!!
:
I'm a rookie programmer this is how i write.
#include <string.h> //ill make it simple for you here
#include <iostream.h> //same thing not following standard as im bad at it too
int main()
{
  string str1 = "ALPHA";
  cout<<str1;
  getchar();
}


Use Visual C++ Express since most people I've asked seem to use it. Go with the flow.
Report
Re: string data type Posted by MT2002 on 17 Apr 2008 at 8:49 PM
Err... no. It is not only bad programming practice, but is also not standards compliant (It may not work on all compilers.)

Just because it "works" does not make it "correct". Don't do it.

Your code should be this:
#include <string>
#include <iostream>
int main()
{
  std::string str1 = "ALPHA";
  std::cout<<str1;
  std::cin.get();
}


I second Visual C++ though In either case, Borland 5.5 will work as well. Cannot do much to help the OP without knowing the error message though...


[.:EvolutionEngine][.:MicroOS Operating System][Website :: OS Development Series]



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - 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 our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.