String Format Crash
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: String Format Crash

Hybrid View

  1. #1
    Join Date
    Apr 2009
    Posts
    113

    String Format Crash

    I have question on string formatting.
    It will crash at the line strCombine.Format("%ld000%s", a, "+0800"); when running on Microsoft visual studio 2010 but not in visual studio 2003 by using the exact same code.
    Any idea why?
    Code Snippet:
    Code:
    CString strCombine="";
    time_t a = 150519836000;
    strCombine.Format("%ld000%s", a, "+0800"); //crash at this line at VS2010 but not at VS2003
    However if change to code as below, it will not crash at VS2010 anymore. Just curious why?
    Code:
    CString strCombine="";
    time_t a = 150519836000;
    strCombine.Format("%ld000", a); //after changing this line, it no longer crash anymore
    strCombine= strCombine + "+0800";

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,504

    Re: String Format Crash

    Quote Originally Posted by PHChang View Post
    I have question on string formatting.
    It will crash at the line strCombine.Format("%ld000%s", a, "+0800"); when running on Microsoft visual studio 2010 but not in visual studio 2003 by using the exact same code.
    Any idea why?
    Code Snippet:
    Code:
    CString strCombine="";
    time_t a = 150519836000;
    strCombine.Format("%ld000%s", a, "+0800"); //crash at this line at VS2010 but not at VS2003
    However if change to code as below, it will not crash at VS2010 anymore. Just curious why?
    Code:
    CString strCombine="";
    time_t a = 150519836000;
    strCombine.Format("%ld000", a); //after changing this line, it no longer crash anymore
    strCombine= strCombine + "+0800";
    Using lld instead of ld in your format string fixes it. I'm not sure what changed between versions though.

  3. #3
    Join Date
    Apr 2009
    Posts
    113

    Re: String Format Crash

    OK thanks for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)