Howdy, Stranger!

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

Categories

data type string

neo5644neo5644 Member Posts: 5
hey guys,
i am beginner at C++. i was wondering if i have to use the declaration "string name;" what includes do i have to specify..coz the textbook i am refering to doesnt specify anything and my turbo C++ version 3 compiler gives an error for the above declaration. advice needed..
Neo

Comments

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : hey guys,
    : i am beginner at C++. i was wondering if i have to use the declaration "string name;" what includes do i have to specify..coz the textbook i am refering to doesnt specify anything and my turbo C++ version 3 compiler gives an error for the above declaration. advice needed..
    : Neo
    :
    [blue]Try [b]String[/b] type.
    Also, do not forget to go to linker options and assign the CLASSLIB library.[/blue]
  • Geeth AsokanGeeth Asokan Member Posts: 127
    : hey guys,
    : i am beginner at C++. i was wondering if i have to use the declaration "string name;" what includes do i have to specify..coz the textbook i am refering to doesnt specify anything and my turbo C++ version 3 compiler gives an error for the above declaration. advice needed..
    : Neo
    :

    Hi,

    I don't use the turbo C++ compiler but try this:

    [code]

    #include
    #include

    int main()
    {
    char name[25];

    std::cout << "Please enter your name: " << std::endl;
    std::cin.getline(name, 25);

    return 0;
    }
    [/code]

    [b]cin.getline( , )[/b] requires the header file [b]#include <cstring>[/b] and the best thing is that [b]cin.getline( , )[/b] includes 'spaces'.

    Hope this helps,

  • brtkltbrtklt Member Posts: 237
    I have problems compiling sometimes when using the string data type b/c I forget to include the header file. If you're still having problems try:

    [code]
    #include
    #include

    int main()
    {
    string someString = "This is a string
    ";
    cout << someString;
    return 0;
    }


    : : hey guys,
    : : i am beginner at C++. i was wondering if i have to use the declaration "string name;" what includes do i have to specify..coz the textbook i am refering to doesnt specify anything and my turbo C++ version 3 compiler gives an error for the above declaration. advice needed..
    : : Neo
    : :
    :
    : Hi,
    :
    : I don't use the turbo C++ compiler but try this:
    :
    : [code]
    :
    : #include <iostream>
    : #include
    :
    : int main()
    : {
    : char name[25];
    :
    : std::cout << "Please enter your name: " << std::endl;
    : std::cin.getline(name, 25);
    :
    : return 0;
    : }
    : [/code]
    :
    : [b]cin.getline( , )[/b] requires the header file [b]#include <cstring>[/b] and the best thing is that [b]cin.getline( , )[/b] includes 'spaces'.
    :
    : Hope this helps,
    :
    :

  • Dirty11Dirty11 Member Posts: 3
    I am new to C++ so sorry for the stupid question.

    what is " std:: " for i never had to use it, i deleted it and the programm executes without it. can anyone say what it does?

    THanks in advance.






    : I have problems compiling sometimes when using the string data type b/c I forget to include the header file. If you're still having problems try:
    :
    : [code]
    : #include
    : #include
    :
    : int main()
    : {
    : string someString = "This is a string
    ";
    : cout << someString;
    : return 0;
    : }
    :
    :
    : : : hey guys,
    : : : i am beginner at C++. i was wondering if i have to use the declaration "string name;" what includes do i have to specify..coz the textbook i am refering to doesnt specify anything and my turbo C++ version 3 compiler gives an error for the above declaration. advice needed..
    : : : Neo
    : : :
    : :
    : : Hi,
    : :
    : : I don't use the turbo C++ compiler but try this:
    : :
    : : [code]
    : :
    : : #include <iostream>
    : : #include
    : :
    : : int main()
    : : {
    : : char name[25];
    : :
    : : std::cout << "Please enter your name: " << std::endl;
    : : std::cin.getline(name, 25);
    : :
    : : return 0;
    : : }
    : : [/code]
    : :
    : : [b]cin.getline( , )[/b] requires the header file [b]#include <cstring>[/b] and the best thing is that [b]cin.getline( , )[/b] includes 'spaces'.
    : :
    : : Hope this helps,
    : :
    : :
    :
    :

  • Geeth AsokanGeeth Asokan Member Posts: 127
    Hi,

    Well, in some compilers one has to include std::

    :: is called the 'Scope resolution operator' and it calls an object belonging to a class.

    So std:: calls an object belonging to the std class.

    In some compilers, one can just do the following.

    [code]
    #include
    #include

    int main()
    {
    char name[25];

    cout << "Please enter your name: " << endl;
    cin.getline(name, 25);

    return 0;
    }
    [/code]

    but the proper way to write the code is:

    [code]
    #include <iostream>
    #include

    int main()
    {
    char name[25];

    std::cout << "Please enter your name: " << std::endl;
    std::cin.getline(name, 25);

    return 0;
    }
    [/code]

    as this works for all compilers.

    Hope this helps,


    : I am new to C++ so sorry for the stupid question.
    :
    : what is " std:: " for i never had to use it, i deleted it and the programm executes without it. can anyone say what it does?
    :
    : THanks in advance.
    :
    :
    :
    :
    :
    :
    : : I have problems compiling sometimes when using the string data type b/c I forget to include the <string> header file. If you're still having problems try:
    : :
    : : [code]
    : : #include
    : : #include
    : :
    : : int main()
    : : {
    : : string someString = "This is a string
    ";
    : : cout << someString;
    : : return 0;
    : : }
    : :
    : :
    : : : : hey guys,
    : : : : i am beginner at C++. i was wondering if i have to use the declaration "string name;" what includes do i have to specify..coz the textbook i am refering to doesnt specify anything and my turbo C++ version 3 compiler gives an error for the above declaration. advice needed..
    : : : : Neo
    : : : :
    : : :
    : : : Hi,
    : : :
    : : : I don't use the turbo C++ compiler but try this:
    : : :
    : : : [code]
    : : :
    : : : #include <iostream>
    : : : #include
    : : :
    : : : int main()
    : : : {
    : : : char name[25];
    : : :
    : : : std::cout << "Please enter your name: " << std::endl;
    : : : std::cin.getline(name, 25);
    : : :
    : : : return 0;
    : : : }
    : : : [/code]
    : : :
    : : : [b]cin.getline( , )[/b] requires the header file [b]#include <cstring>[/b] and the best thing is that [b]cin.getline( , )[/b] includes 'spaces'.
    : : :
    : : : Hope this helps,
    : : :
    : : :
    : :
    : :
    :
    :

  • tyron123tyron123 Member Posts: 68
    the scope resolution operatior is not required in new versions of the c compiler, as in the older one is suppose the library path was not specified, shte std:: is usually used to call a function from a class, where std is the class name and :: is scope resolutor used to gain access to that class, its some thin that u will learn later on!
    ===================================================================
    : Hi,
    :
    : Well, in some compilers one has to include std::
    :
    : :: is called the 'Scope resolution operator' and it calls an object belonging to a class.
    :
    : So std:: calls an object belonging to the std class.
    :
    : In some compilers, one can just do the following.
    :
    : [code]
    : #include
    : #include
    :
    : int main()
    : {
    : char name[25];
    :
    : cout << "Please enter your name: " << endl;
    : cin.getline(name, 25);
    :
    : return 0;
    : }
    : [/code]
    :
    : but the proper way to write the code is:
    :
    : [code]
    : #include <iostream>
    : #include
    :
    : int main()
    : {
    : char name[25];
    :
    : std::cout << "Please enter your name: " << std::endl;
    : std::cin.getline(name, 25);
    :
    : return 0;
    : }
    : [/code]
    :
    : as this works for all compilers.
    :
    : Hope this helps,
    :
    :
    : : I am new to C++ so sorry for the stupid question.
    : :
    : : what is " std:: " for i never had to use it, i deleted it and the programm executes without it. can anyone say what it does?
    : :
    : : THanks in advance.
    : :
    : :
    : :
    : :
    : :
    : :
    : : : I have problems compiling sometimes when using the string data type b/c I forget to include the <string> header file. If you're still having problems try:
    : : :
    : : : [code]
    : : : #include
    : : : #include
    : : :
    : : : int main()
    : : : {
    : : : string someString = "This is a string
    ";
    : : : cout << someString;
    : : : return 0;
    : : : }
    : : :
    : : :
    : : : : : hey guys,
    : : : : : i am beginner at C++. i was wondering if i have to use the declaration "string name;" what includes do i have to specify..coz the textbook i am refering to doesnt specify anything and my turbo C++ version 3 compiler gives an error for the above declaration. advice needed..
    : : : : : Neo
    : : : : :
    : : : :
    : : : : Hi,
    : : : :
    : : : : I don't use the turbo C++ compiler but try this:
    : : : :
    : : : : [code]
    : : : :
    : : : : #include <iostream>
    : : : : #include
    : : : :
    : : : : int main()
    : : : : {
    : : : : char name[25];
    : : : :
    : : : : std::cout << "Please enter your name: " << std::endl;
    : : : : std::cin.getline(name, 25);
    : : : :
    : : : : return 0;
    : : : : }
    : : : : [/code]
    : : : :
    : : : : [b]cin.getline( , )[/b] requires the header file [b]#include <cstring>[/b] and the best thing is that [b]cin.getline( , )[/b] includes 'spaces'.
    : : : :
    : : : : Hope this helps,
    : : : :
    : : : :
    : : :
    : : :
    : :
    : :
    :
    :

  • brtkltbrtklt Member Posts: 237
    You can simplify things by avoiding using the scope resolution operator anytime you're using a namepace (in this case namespace std) by using a "using directive":

    using namespace std;

    I usually do this after the includes

    : the scope resolution operatior is not required in new versions of the c compiler, as in the older one is suppose the library path was not specified, shte std:: is usually used to call a function from a class, where std is the class name and :: is scope resolutor used to gain access to that class, its some thin that u will learn later on!
    : ===================================================================
    : : Hi,
    : :
    : : Well, in some compilers one has to include std::
    : :
    : : :: is called the 'Scope resolution operator' and it calls an object belonging to a class.
    : :
    : : So std:: calls an object belonging to the std class.
    : :
    : : In some compilers, one can just do the following.
    : :
    : : [code]
    : : #include
    : : #include
    : :
    : : int main()
    : : {
    : : char name[25];
    : :
    : : cout << "Please enter your name: " << endl;
    : : cin.getline(name, 25);
    : :
    : : return 0;
    : : }
    : : [/code]
    : :
    : : but the proper way to write the code is:
    : :
    : : [code]
    : : #include <iostream>
    : : #include
    : :
    : : int main()
    : : {
    : : char name[25];
    : :
    : : std::cout << "Please enter your name: " << std::endl;
    : : std::cin.getline(name, 25);
    : :
    : : return 0;
    : : }
    : : [/code]
    : :
    : : as this works for all compilers.
    : :
    : : Hope this helps,
    : :
    : :
    : : : I am new to C++ so sorry for the stupid question.
    : : :
    : : : what is " std:: " for i never had to use it, i deleted it and the programm executes without it. can anyone say what it does?
    : : :
    : : : THanks in advance.
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : : : I have problems compiling sometimes when using the string data type b/c I forget to include the <string> header file. If you're still having problems try:
    : : : :
    : : : : [code]
    : : : : #include
    : : : : #include
    : : : :
    : : : : int main()
    : : : : {
    : : : : string someString = "This is a string
    ";
    : : : : cout << someString;
    : : : : return 0;
    : : : : }
    : : : :
    : : : :
    : : : : : : hey guys,
    : : : : : : i am beginner at C++. i was wondering if i have to use the declaration "string name;" what includes do i have to specify..coz the textbook i am refering to doesnt specify anything and my turbo C++ version 3 compiler gives an error for the above declaration. advice needed..
    : : : : : : Neo
    : : : : : :
    : : : : :
    : : : : : Hi,
    : : : : :
    : : : : : I don't use the turbo C++ compiler but try this:
    : : : : :
    : : : : : [code]
    : : : : :
    : : : : : #include <iostream>
    : : : : : #include
    : : : : :
    : : : : : int main()
    : : : : : {
    : : : : : char name[25];
    : : : : :
    : : : : : std::cout << "Please enter your name: " << std::endl;
    : : : : : std::cin.getline(name, 25);
    : : : : :
    : : : : : return 0;
    : : : : : }
    : : : : : [/code]
    : : : : :
    : : : : : [b]cin.getline( , )[/b] requires the header file [b]#include <cstring>[/b] and the best thing is that [b]cin.getline( , )[/b] includes 'spaces'.
    : : : : :
    : : : : : Hope this helps,
    : : : : :
    : : : : :
    : : : :
    : : : :
    : : :
    : : :
    : :
    : :
    :
    :

  • dundideatdundideat Member Posts: 12
    : hey guys,
    : i am beginner at C++. i was wondering if i have to use the declaration "string name;" what includes do i have to specify..coz the textbook i am refering to doesnt specify anything and my turbo C++ version 3 compiler gives an error for the above declaration. advice needed..
    : Neo
    :
    Hi Neo,
    I agree with most of the other users, but my answer should be brief and to the point.
    - C header file; No string types in C;
    - C++ header file; Need to include using namespace std;
    - C++ header file; Don't need to include namespace;
    If you need more details feel free to contact me.
  • Andre YoungAndre Young USAMember Posts: 0

    ____ ( http://forcoder.org ) free ebooks and video tutorials about { Assembly Ruby Perl Delphi Visual Basic .NET Swift PHP R JavaScript Visual Basic C# Python Go Scratch C++ Objective-C MATLAB C PL/SQL Java Dart Lisp Prolog D Hack COBOL Fortran Crystal Bash Apex FoxPro Rust Erlang Logo Lua Transact-SQL Julia Scala Kotlin Awk VBScript LabVIEW Ada ML F# Alice Scheme ABAP SAS Clojure } _

Sign In or Register to comment.