%3s equivalent for C++

This is a discussion on %3s equivalent for C++ within the C++ Programming forums, part of the General Programming Boards category; what happens if i have a char array [20] and i want to print only the first 3 letters of ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    71

    %3s equivalent for C++

    what happens if i have a char array [20]
    and i want to print only the first 3 letters of the string

    what c++ function would i use?

    the idea is that i have a ssn [10]
    and i want to display it as 1234-56-789

    i could use C functions but i dont want to do that
    and i could print them one char at a time in a for loop but i am wondering if there are c++ functions for that
    something like setprecision (though that is for numbers)
    u get the idea

    cheers

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    If you don't wanna use sprintf, why not use the string class?

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    71
    cuz the teacher hasnt taught it yet
    but i dont mind using the string class just that i havent used string data types

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,673
    cout.write(ssn,3);
    I used to be an adventurer like you... then I took an arrow to the knee.

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    71
    Originally posted by hk_mp5kpdw
    cout.write(ssn,3);
    silly me
    i have learnt it but never used it
    Last edited by mackol; 03-17-2003 at 05:16 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer equivalent to array notation
    By bekkilyn in forum C Programming
    Replies: 4
    Last Post: 12-06-2006, 07:22 PM
  2. C++ Equivalent JPEG Functions?
    By stickman in forum C++ Programming
    Replies: 9
    Last Post: 05-06-2006, 10:50 AM
  3. Replies: 10
    Last Post: 08-17-2005, 11:17 PM
  4. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 10:31 PM
  5. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 06:18 AM

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