Thread: Problems using ostringstreams

  1. #1
    Registered User
    Join Date
    Jan 2007

    Question Problems using ostringstreams

    Well I've been trying to get a code to loop a customer ID number, where it adds one each loop. I then wanted this number to become the title of a .txt that would display the customer or user's transaction.
    My problem is that the string won't become flushed, and it just keeps compounding the next loops id and ".txt" making the first file name 1.txt and the second 1.txt2.txt . A simple ID.flush(); doesn't seem to do the trick, what am i missing??

  2. #2
    Registered User
    Join Date
    Jan 2005
    You could declare the ostringstream inside the loop, which is generally good practice anyway (declare variables as locally as possible unless you have a specific reason not to).

    Otherwise, use str("") to empty the stream contents before starting the next iteration of the loop.

  3. #3
    Registered User
    Join Date
    Jan 2007


    Your first solution works beautifully.
    Thanks alot!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 05:35 AM
  3. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 08:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 03:35 PM
Website Security Test