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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:36:22+00:00 2026-06-15T14:36:22+00:00

I have a text file that reads: this is an email file with DummyTest@my.test

  • 0

I have a text file that reads:

this is an email file with DummyTest@my.test and some other text for the test
ATest@my.test
BTest@my.test

And then I have a substr (s, e - s), where s is the start of the line and e is the end that will give me this:

terminate called after throwing an instance of 'std::out_of_range'
what():  basic_str`entering::substr
Aborted

This only occurs for the bottom two lines, and the first will print DummyTest@my.test

The problem I know is what is happening is when s is at the beginning of the line and there are no characters before it (i.e. “ATest@my.test” or “BTest@my.test”), this error occurs. What could be added to prevent this from occuring?

while (getline(fin, lines))
{
for (int i = 0; i < lines.length(); i++)
{
if (lines[i] == '@')
{
int s;

if (i == 0 || i == 1) break;
for (s = i - 1; s < lines.length() ; s--)
{
if(validChar(lines[s]) == false )
 {
 s = s + 1;
 break;
 }
} //for 

 int e; 
 bool hasDot = false;  

 for (e = i + 1; e < lines.length(); e++)
 {
 if (e == lines.length()) break;
 if(validChar(lines[e]) == false )
 {
 break;
 } // if in for

 if(lines[e] == '.') hasDot = true;
 } // for 

anEmail = lines.substr (s,  e - s);
if (s < i && e > i && hasDot == true)
cout << anEmail << 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-06-15T14:36:23+00:00Added an answer on June 15, 2026 at 2:36 pm

    Obviously, one of your paramaters are out of range becase of the out_of_range exception that was thrown. I would run some test to make sure that the values s and e are what you would expect them to be.

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

Sidebar

Related Questions

We have some C# code that reads data from a text file using a
/edited/ I'm new here. I have a text file that reads: 6 <cr> R
I have a simple java code that reads text csv file that contains sentences
I have an app that reads a huge text file (about more than 100MB)
I have a method that reads data from a comma separated text file and
I have a small Java program that reads list of IPs from text file
I Have a program written in VB6 that reads a long text file and
I have a Qt application, that reads a special text file, parses it and
I have a Python script that reads through a text csv file and creates
I have a large text file that reads like Kyle 40 Greg 91 Reggie

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.