string data type - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

string data type

perfectvijayperfectvijay Posts: 10Member
hi actually i wanted to use a string data type available in c++. i tried to use it like this

#include
....
....
{
string str("ALPHA");
}
it is giving an error and am using turbo 3.0 c++ compiler..
plz help me!!!

Comments

  • LundinLundin Posts: 3,711Member
    Correct syntax is

    #include
    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.


  • perfectvijayperfectvijay Posts: 10Member
    i did that also but still not working i teied it on bc++ 5 also still not working!!

  • LundinLundin Posts: 3,711Member
    Post compiler messages.
  • ColacXColacX Posts: 141Member
    : hi actually i wanted to use a string data type available in c++. i
    : tried to use it like this
    :
    : #include
    : ....
    : ....
    : {
    : 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.
    [code]
    #include //ill make it simple for you here
    #include //same thing not following standard as im bad at it too
    int main()
    {
    string str1 = "ALPHA";
    cout<<str1;
    getchar();
    }
    [/code]

    Use Visual C++ Express since most people I've asked seem to use it. Go with the flow.
  • MT2002MT2002 Posts: 1,444Member
    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". [b]Don't do it.[/b]

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

    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...

    [hr][size=1][leftbr].:EvolutionEngine[rightbr][leftbr].:MicroOS Operating System[rightbr][leftbr][link=http://www.brokenthorn.com]Website :: OS Development Series[rightbr][/link][/size]
  • perfectvijayperfectvijay Posts: 10Member
    i used bc++ 5 but still its not working..

  • MT2002MT2002 Posts: 1,444Member
    : 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.
    [hr][size=1][leftbr].:EvolutionEngine[rightbr][leftbr].:MicroOS Operating System[rightbr][leftbr][link=http://www.brokenthorn.com]Website :: OS Development Series[rightbr][/link][/size]
Sign In or Register to comment.