1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Rep Power

    String input and manipulation.

    Hey guys. I've been stuck on an assignment, and it's an online course so the professor hasn't responded to my email for a couple of days. I'm supposed to make a program that does the following:
    1. Reads in a line consisting of a studentís name, Social Security number, user ID, and password.
    (This part is obvious, no issues here).

    2. Output the string in which all the digits of the Social Security number, and all the characters in the password are replaced by x.
    (This is where I'm having trouble)

    I believe I'll need to use several string functions to achieve this, such as strVar.length() or strVar.size(), strVar.find_first_not_of (),
    strVar.erase(), strVar.swap().

    I'm wondering if it's possible to use strVar.find_first_not_of() to find the first of any integer (since the input goes Name, SSN, ID, password). Then use the swap function?

    If anyone's at all familiar with string manipulation, I'd greatly appreciate some advice. Thanks
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Rep Power
    What are the rules to find tokens in the input?
    If you knew the index of the ends of the password I would think this code ought to help:

    for (i=left;i<right;++i) the_string[i] = 'x';

    The interval [left, right) is inclusive on left, exclusive at right.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo