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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:11:14+00:00 2026-06-12T16:11:14+00:00

So, here’s my code. I have to remove all ‘a’ and ‘A’ from the

  • 0

So, here’s my code. I have to remove all ‘a’ and ‘A’ from the given text (which can be random) but here is the text block sample I’m given:

The quick brown fox jumps over a lazy dog. A
cat ran away as the fox came around the bend.
Further down the road, a student was ta-
king an exam for his CS2433 class.

I’ve added a couple other cout’s just to see along the way what’s going on and it appears my cin is only taking in the “The” part of the given text to read in.

I’m not sure what’s going on? The unix command I use to run the file with an input file is: ./hw5.out < hw5in.txt
Should I use something different to pass in the string?

1 #include <iostream>
2 #include <algorithm>
3 using namespace std;
4
5 int main()
6 {
7
8    string str;
9    cin >> str;
10
11    char chars[] = "aA";
12    cout << str;
13    for (unsigned int i = 0; i < str.length(); i++)
14    {
15 
16
17       str.erase (std::remove(str.begin(), str.end(), chars[i]), str.end());
18    }
19    cout << str;
20    for (int i = 0; i < str.length();i++)
21    {
22       if (str[i] == '\n')
23       {
24          str[i] = '\t';
25       }
26    }
27
28 
29    cout << str;
30
31 }

UPDATE: I wrote out a while look with the getLine command concatenating each iteration into a variable “text” and then ran some of what my original code did, replacing all the str’s with text. I appreciate the responses, I’ll definitely being going through the repositories posted, thanks!

  • 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-12T16:11:15+00:00Added an answer on June 12, 2026 at 4:11 pm

    To expand on the answer from @cnicutar and fix some other things in your code:

    #include <iostream>
    #include <algorithm>
    #include <string>
    
    int main()
    {
        char* to_remove = "aA";
    
        while (!std::cin.eof())
        {
            std::string str;
            std::getline(std::cin, str);
    
            if (std::cin.fail())
            {
                std::cerr << "Error reading from STDIN" << std::endl;
                return 1;
            }
    
    
            size_t index = 0;
    
            while ((index = str.find_first_of(to_remove, index)) != string::npos)
            {
                str.erase(index);
            }
    
            std::cout << str << std::endl;
        }
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Here's a piece of code I copied from http://www.schillmania.com/content/projects/javascript-animation-1/demo/ Very simple JS animation: function
Here is my program to find all the subsets of given set. To solve
Here are the tables I have: Table A which has entries with item and
Here's the code I have. It works. The only problem is that the first
Here is my code, which takes two version identifiers in the form 1, 5,
here is my code, SiteMember class @OneToMany(mappedBy = member,cascade=CascadeType.ALL) private List<MemberThread> memberThread = new
Here is the code from my project where I am using a datepicker. The
Here a simple question : What do you think of code which use try

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.