trying to use arrays and string manipulators

This is a discussion on trying to use arrays and string manipulators within the C++ Programming forums, part of the General Programming Boards category; thanks...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    8
    thanks
    Last edited by nadeni0119; 03-24-2003 at 09:50 PM.

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

    ?

    You want :
    - the user to input a number and instead of digits the user should see * ?

  3. #3
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    You want to input a string but output *'s? In that case then you could probably use a loop of getchars and cout a * for every character read, store it in an array of chars and then if they press a backspace you could always move backwards in the array one character.

    That is, if thats what you mean.

    ~ Paul

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

    Wink Yes

    So, that is the Idea. But, if You want somth else, please reply

  5. #5
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    I can't remember if it's in <iostream> or <iomanip>, but there exists a function fill that will fill the leading whitespace with the character of your choice so that you could do something like:
    Code:
    ***************$123.45
    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
    Nov 2002
    Posts
    1,109
    you need to #include "apstring.h" or I believe borland can do #include <apstring.h>

    the two errors are because of this missing include.

    edit: but if this is part of an AP class, and you have the header file, it should be in " ", such as the first example.

  7. #7
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    I'm not familiar with "apstring".

    on line 10 you have:
    apstring amount;// invalid: apstring has not been declared (but you could say
    string amount;


    on line 15:
    while(x < amount.length());// for this to work you must fix the previous error first

    You don't need that loop to find the '.'; look up the find() function which you can use to locate the decimal point.
    But anyway, WHY are you looking for the decimal point, and what are you trying to do with "Dollar and" and "cents", since you said that you want to print this ****99.87 format?

    If your dollar amount is in a string you can use insert() to place a $in front of the amount (look up string functions for the parameters).

    Then you can use
    cout << setw(n) where n is the desired field width
    and
    cout << setfill(*) to fill the field with leading *s.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Separate long string into multiple arrays
    By cashmerelc in forum C Programming
    Replies: 6
    Last Post: 11-27-2007, 01:57 AM
  2. String Compare Using Dynamic Arrays
    By djwicks in forum C Programming
    Replies: 4
    Last Post: 03-31-2005, 07:01 PM
  3. string arrays
    By Raison in forum C Programming
    Replies: 27
    Last Post: 10-02-2003, 06:27 PM
  4. string handling
    By lessrain in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 07:36 PM
  5. Files & String ARrays
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 12-09-2001, 11:13 AM

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