string manipulation, etc.

This is a discussion on string manipulation, etc. within the C++ Programming forums, part of the General Programming Boards category; Ok, so i have to take this older program that i wrote and develop a new input style for it. ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    69

    string manipulation, etc.

    Ok, so i have to take this older program that i wrote and develop a new input style for it. the original type of input was just separate integers of input on separate lines. now, we have to have input on the order of:

    {5,100, 5123}

    and the like. the input must start with the curly brace, and the commas separate values. when we output the user's set, any number that would contain a comma must contain a comma. for example:

    {5, 100, 5,123}

    as per the previous input. this last part i can't figure out... how can you insert a comma as part of the output of values?

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    think / and %

  3. #3
    Registered User sikamikaniko's Avatar
    Join Date
    Mar 2003
    Posts
    28

    If you want to do this ...

    to output like this {1,2,3}
    do it
    cout<<"{"<<arr[0]<<"," <<arr[1] etc.

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    69
    well, we have to change the output of the number from

    1000

    to

    1,000

    like you would write it longhand with the commas as digit grouping separators

  5. #5
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    If you're only dealing with positive numbers less than a million, you could do something like this:
    Code:
    int num = 12345;
    cout << num/1000 << ',' << num%1000;
    The output there would be: 12,345
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    69
    that will be a great part of the code for the positive numbers, but it also has to have a condition for negative numbers........ the valild input will be in the range +32999 to -32999 or something... i'll probably use that for the positive values if it's easier than the code for negative values.

  7. #7
    Registered User
    Join Date
    Oct 2002
    Posts
    69
    one problem with that little piece of code......... if the remainder portion has leading zeros, it won't display them. if you have 1000, i will display 1,. if you have 1002 it will display 1,2. i'll try to find a way around that myself for now though. ya know, so i can "further my education" and whatnot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 07:02 AM
  2. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 10:19 AM
  3. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  5. string manipulation
    By SPEKTRUM in forum Linux Programming
    Replies: 3
    Last Post: 01-26-2002, 11:41 AM

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