Strings for Non-char Data Types?

This is a discussion on Strings for Non-char Data Types? within the C++ Programming forums, part of the General Programming Boards category; Is it possible (or practical) to use strings to hold data types other than text strings and characters?...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    194

    Strings for Non-char Data Types?

    Is it possible (or practical) to use strings to hold data types other than text strings and characters?

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    A string holding text strings is definitely not useful.

    A basic_string of wchar_t is very useful and even has its own typedef wstring (just as string is a typedef for a basic_string of char).

    If you want other types, which is certainly possible and can be useful for some character encodings, you need to specialize the char_traits template on this type.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    You mean like std::vector<unsigned char> ?
    That should be able to store any kind of bytes from 0x00 to 0xFF.

  4. #4
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,532
    It's possible, but not practical.
    int, char, BOOL, HANDLE, are all just different size byte groups; For example, char[4] can hold the exact same data as int.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 11:36 AM
  3. Need help fixing bugs in data parsing program
    By daluu in forum C Programming
    Replies: 8
    Last Post: 03-27-2003, 05:02 PM
  4. Strings are V important...
    By NANO in forum C++ Programming
    Replies: 15
    Last Post: 04-14-2002, 11:57 AM

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