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

  • Home
  • SEARCH
  • 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 6009633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:59:56+00:00 2026-05-23T01:59:56+00:00

I have written code for performing calculations. There is a loop in the code.

  • 0

I have written code for performing calculations. There is a loop in the code. Each loop corresponds to a different time.

For each loop, I want to write a string to an external file. The string should contain “filename_” and the number of the loop–for example:

‘fileName_4’

The problem is that it is appearing as (with the closing ‘ on the line below):

‘fileName_4
‘

If anyone could help, I would be very grateful. Here is what I have tried:

std::string       convertedToString;
std::stringstream numberConverted; 

storeNumberForConversion << time << endl;   // time is a number, like the 4 in the example above
convertedToString = numberConverted.str() += "'";


fileNameHighestTimeStream.open ("fileName.txt", ios::out | ios::app );
fileNameHighestTimeStream << "'fileName_" << convertedToString << endl; 
fileNameHighestTimeStream.close();

I have also tried:

storeNumberForConversion << time << endl;   // time is a number, like the 4 in the example above
convertedToString = numberConverted.str();


fileNameHighestTimeStream.open ("fileName.txt", ios::out | ios::app );
fileNameHighestTimeStream << "'fileName_" << convertedToString << "'" << endl; 
fileNameHighestTimeStream.close();
  • 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-05-23T01:59:56+00:00Added an answer on May 23, 2026 at 1:59 am
    std::string       convertedToString;
    std::stringstream numberConverted; 
    
    storeNumberForConversion << time << endl;   // time is a number, like the 4 in the example above
    convertedToString = numberConverted.str() += "'";
    

    Presumably this is a typo, and you have:

    std::string       convertedToString;
    std::stringstream numberConverted; 
    
    numberConverted << time << endl;   // time is a number, like the 4 in the example above
    convertedToString = numberConverted.str() += "'";
    

    You streamed endl to numberConverted, so it contains a newline. Simple!

    From your comment elsewhere:

    I thought the endl would flush the stream? If I DON’T include the endl, should I worry about flushing the stream? If so, how would I do it without endl?

    << endl is the same as << '\n' << flush. So you can still do the flushing yourself with << flush, but actually usually you should just leave this up to the stream object to handle in its own time.

    Also the use of += is suspect (though it happens to yield the correct result in this case).

    Fixed:

    std::stringstream numberConverted;
    numberConverted << time;
    
    std::string       convertedToString;
    convertedToString = numberConverted.str() + "'";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a few modules of code in Access vba. Each code runs
I have written code that automatically creates CSS sprites based on the IMG tags
I have written some code in my VB.NET application to send an HTML e-mail
I have written jQuery code, in files Main.html and ajax.php . The ajax.php file
Here's a snippet of code from a shell script I have written: for src
Put it another way: what code have you written that cannot fail. I'm interested
I have just been re-working an old bit of compiler-like code written using bison.
I have a code snippet written in PHP that pulls a block of text
I have some code I've written in PHP for consuming our simple webservice, which
I have the source code of an application written in C++ and I just

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.