Thread: Inserting contents of string into an array

  1. #1
    Code Injector Gaming's Avatar
    Join Date
    Mar 2008

    Talking Inserting contents of string into an array

    How do you take a string full of letters and spaces and put them all into an array? I'm thinking pointers, but I'm not sure.

    For example:
    string random = "hello everyone";
    int array[50];
    //how would i put the contents of that string into array?

    Any help would be appreciated. Thanks.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    The array holds integers. What do you expect to happen when you say that you want to put the string contents there?
    All the buzzt!

    "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
    Code Injector Gaming's Avatar
    Join Date
    Mar 2008
    Hm, thats what I was thinking. I was thinking alphabetical substitution. Encrypting it into integers, and when printing it out, decrypts it back to characters. Thanks for reminding me!! I'll post my code here once I'm finished. Thanks again xD!

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    What purpose would this array serve? Note that the characters of std::string are integers of type char.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Like this maybe:

    char *name[ 2 ] = { "hello", "hello there" };
    Double Helix STL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. can't assign proper values to an array of string
    By Duo in forum C Programming
    Replies: 1
    Last Post: 04-04-2005, 06:30 AM
  4. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM