what variable

This is a discussion on what variable within the C++ Programming forums, part of the General Programming Boards category; What Variable should I use to store text...

  1. #1
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161

    what variable

    What Variable should I use to store text

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Look at C-style string (char*'s) or, the preferable std::string class in <string> (C++ Standard Library).
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  3. #3
    C Programmer Stack Overflow's Avatar
    Join Date
    Apr 2004
    Posts
    477
    Since this is the C++ area, I would suggest a string. You can learn all about it here.


    - Stack Overflow
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  4. #4
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Don't worry, the link Stack Overflow provided is a good reference, but the string class is much easier to use than reading that page would suggest. I don't know of any specific tutorials on string that would be easier to follow, but I'm sure there are some.

  5. #5
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161

    Cool

    thanks everyone

  6. #6
    C Programmer Stack Overflow's Avatar
    Join Date
    Apr 2004
    Posts
    477
    Oh,

    I must admit it is a good reference compared to learning about it. Here are some tutorials that you may find helpful:


    - Stack Overflow
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  7. #7
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Nice, thank you. Upon quick skimming I like the fourth one best.

  8. #8
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,802
    Yeah but the third one didn't exactly give me the warm fuzzies:

    A string is a sequence of characters. In order to use strings in your programs, you need to first make sure that you are using a recognized string library. This can be achieved by adding the following to the top of your code (where you place your header files):

    #include<string.h>

    using namespace std;

    The second line tells the compiler to use the standard "namespace" for the string library.
    That using namespace std; line doesn't have anything to do with the string.h header does it? Maybe string but not string.h. Also, I wouldn't say that simply including a header lets you "recognize" the string library.


    The rest is fairly simple. Here is how a sample program using strings would look like:

    #include <iostream>
    #include <string>

    using namespace std;

    void main() // Yuck
    {
    string firstname="test";

    cout << "Enter first name: ";
    cin >> firstname;

    cout << firstname << endl;

    }
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  9. #9
    C Programmer Stack Overflow's Avatar
    Join Date
    Apr 2004
    Posts
    477
    Some tutorials don't give accurate information. It is hard to find tutorials on <string>, so I just posted all the information I had. Sadly, some people still use incorrect syntax and other idio's like void main() when they shouldn't. A post I made a while back shows why it isn't good to use these types of coding practices.


    - Stack Overflow
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 11:07 AM
  2. Use of variable
    By alice in forum C Programming
    Replies: 8
    Last Post: 06-05-2004, 07:32 AM
  3. Replies: 2
    Last Post: 04-12-2004, 01:37 AM
  4. write Variable and open Variable and get Information
    By cyberbjorn in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2004, 01:30 AM
  5. Variable question I can't find answer to
    By joelmon in forum C++ Programming
    Replies: 3
    Last Post: 02-12-2002, 03:11 AM

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