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 7598819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:30:16+00:00 2026-05-30T22:30:16+00:00

I was coding something and my code didn’t work correctly in some situations, so

  • 0

I was coding something and my code didn’t work correctly in some situations, so I decided to write some output to file for debugging. The program just concatenates some characters from a string (and it didn’t get out of bounds) and printed them to the file. It has no thing as error reporting or something, and the input string is just a bunch of random characters. But, i get some junk in the output, such as:

f::xsgetn error reading the file
sgetn error reading the file
ilebuf::xsgetn error reading the file

(I removed program’s output and this is just the extra stuff.)

As far as I know, if there are any errors, an exception must be thrown. What happens and how can I fix it?

The same thing happens when I print the output using standard output. All used libraries are standard libraries (eg. iostream, fstream, etc.)

PS: For some reasons, I can’t publish all the code. Here is the part that creates the output and passes it to stream: (tri is and string, and is defined previously. Center is an integer and is inside the bounds of the string. fout is a previously defined file stream.)

string op = "" + tri[center];
fout << center << "<>" << op << endl;
  • 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-30T22:30:17+00:00Added an answer on May 30, 2026 at 10:30 pm

    Since tri is a string, tri[center] is a char.
    The type of "" is const char[], which can’t be added to a char.
    Instead it is implicitly converted to const char*, which can be added to a char.

    Unfortunately for you, the result of that is that the integer value of tri[center]is added to that pointer as an offset, not as a string concatenation, and the particular area of memory that the result refers to doesn’t contain what you’re looking for but instead contains other static strings like e.g. “error reading the file”.

    To fix it, use

    string op = string(“”) + tri[center];

    instead.

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

Sidebar

Related Questions

Say you're coding some kind of web application. Something where people can contribute content,
we have here at work a very strange coding convention, and I didn't managed
I started coding something complicated and then realized my event handlers don't work, so
I have done some basic Perl coding but never something in python. I would
Today while i was coding , I encounter something which I didn't expect it
I have some code that uses ctypes to try to determine if the file
First off, I'm a complete beginner at C++. I'm coding something using an API,
I've noticed something about my coding that is slightly undefined. Say we have a
I have an entity which looks something like this: (I'm coding to the web
In Objective-C on Apple there is something called Key-Value Coding that allows you to

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.