Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8290469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:49:27+00:00 2026-06-08T12:49:27+00:00

Possible Duplicate: How to clear stringstream? I have this c++ command //siteurl and filename

  • 0

Possible Duplicate:
How to clear stringstream?

I have this c++ command

//siteurl and filename are of string type


stringstream ss;
ss << "lynx -dump '" << siteurl << "' > " << filename;

On first loop, everything ok. But on second loop i realize it just append instead of create a new record

as i troubleshoot using cout it give me this, I realize the command is append instead of overwrite on 2nd loop, how do I null or reset or overwrite first record of ss (stringstream) on 2nd loop/usage.

Webparser: lynx -dump 'http://sg.finance.yahoo.com/q?s=USDSGD=X' > file.txtlynx -dump 'http://sg.finance.yahoo.com/q?s=EURUSD=X' > file.txt

What i want is on 2nd loop it will be this output

Webparser: lynx -dump 'http://sg.finance.yahoo.com/q?s=EURUSD=X' > file.txt

I am new to C++, thanks for all help, greatly apperciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:49:29+00:00Added an answer on June 8, 2026 at 12:49 pm

    Do ss.str("") to make it empty.

    But it is better to define ss inside the loop, so that each time it’s a new variable:

    for(/*.....*/)
    {
       stringstream ss;
       ss << /*....*/ ;
    }
    

    That is, make it a scope variable, e.g function-scope or block-scope, so that when it goes out of scope it is destructed, and when it comes back, it gets created again.

    Making it a scope variable is less error prone than using ss.str("") to make it empty. I mean, what if you forgot to do ss.str("")? In many cases, when you need to write ss.str("") indicates that you actually need to make it a scope variable, so that you could define it again, either in a loop (as shown above), or entirely a new variable, probably with a different name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: list.clear() vs list = new ArrayList<int>(); I have a list: List<Integer> l1
Possible Duplicate: Reversing an MD5 Hash Given this method in c# public string CalculateFileHash(string
Possible Duplicate: How to clear/empty Java Stringbuilder I'm adding values to a string and
Possible Duplicate: How to clear browser cache with php? I have created a web
Possible Duplicate: Function to Clear the Console in R In bash, its like this:
Possible Duplicate: how to clear my listview in android In android, i have used
Possible Duplicate: Does std::vector.clear() do delete (free memory) on each element? I have a
Possible Duplicate: iOS application: how to clear notifications? is there a way how to
Possible Duplicate: What's the best way to delete all data from a table? Clear
Possible Duplicate: How to properly clean up Excel interop objects in C# I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.