Thread: Looking for a function...

  1. #1
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949

    Looking for a function...

    Is there a function like this:
    nofv(int i, char c)
    That returns a string of i c's? Such as this:
    nofv(5, "m")
    Would return a string of "mmmmm"? Or will I have to make my own? Thanks !
    Do not make direct eye contact with me.

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    161
    Since this is the C++ board, I'm assuming that STL solutions are acceptable. If that's the case, then a std::string constructor will do exactly what you want:
    Code:
      std::string str(5, 'm');
      std::cout << str << std::endl;
      /* output: mmmmm */

  3. #3
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Well, I'm not too excited to use strings (I like them, just char arrays would work better in my case). Thanks anyway !
    Do not make direct eye contact with me.

  4. #4
    Registered User Paragon's Avatar
    Join Date
    Nov 2003
    Posts
    2
    Code:
    #include <iomanip.h>
    
    int main() {
    	cout << setw(6) << setfill('m') << endl;
    	return 0;
    }

  5. #5
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    You would have to pass the array you want to store it in, otherwise you return a pointer to a temporary object...It would be easy to write a function like that, but I think you could just use the memset function
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM