Does strfmt("%s",str) has a length restrict?

This is a discussion on Does strfmt("%s",str) has a length restrict? within the C++ Programming forums, part of the General Programming Boards category; When I use Code: string msg = strfmt("%s\n", str.c_str()); str is a string with size() of 6458, but msg has ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    284

    Does strfmt("%s",str) has a length restrict?

    When I use

    Code:
    string msg = strfmt("%s\n", str.c_str());
    str is a string with size() of 6458, but msg has size() of 1023. What's going on here in strfmt?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,955
    strfmt() appears to be non-standard, so you would need to refer to the relevant docs.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Why not use the standard "sprintf" function? Ok, so you have to muck about a bit more to do that, but it should work. Or use the stringstream class to format a string. Both of these solutions should solve the problem.

    And funnily enough, the first few references to strfmt() that I could find was this question, so I guess it's a pretty unusual function.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Strange string behavior
    By jcafaro10 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 07:38 PM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. Weird modification to string length
    By ChwanRen in forum C Programming
    Replies: 0
    Last Post: 08-17-2003, 10:45 AM
  5. length of string etc.
    By Peachy in forum C Programming
    Replies: 5
    Last Post: 09-27-2001, 12:04 PM

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