data type string

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

  • : 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]
  • : 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,

  • 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,
    :
    :

  • 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,
    : :
    : :
    :
    :

  • 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,
    : : :
    : : :
    : :
    : :
    :
    :

  • 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,
    : : : :
    : : : :
    : : :
    : : :
    : :
    : :
    :
    :

  • 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,
    : : : : :
    : : : : :
    : : : :
    : : : :
    : : :
    : : :
    : :
    : :
    :
    :

  • : 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.
Sign In or Register to comment.

Howdy, Stranger!

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

Categories