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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:11:05+00:00 2026-06-02T15:11:05+00:00

People who learned how to type before word processors often add two spaces after

  • 0

People who learned how to type before word processors often add two spaces after a period ending a sentence. Write a function singleSpaces that accepts a string and returns that string with all occurrences of two spaces after a “.” into changed single spaces.)

This is what I have; what am I doing wrong?

#include <cmath>
#include <iostream>
using namespace std;



string forceSingleSpaces1 (string s) {
    string r = "";
    int i = 0;
    while (i < static_cast <int> (s.length()))  {
        if (s.at(i) != ' ')  {
            r = r + s.at(i);
            i++;
        } else  {
            r +=  ' ';
            while (i < static_cast <int> (s.length()) && s.at(i) == ' ')
                i++;
        }
    }
    return r;
}
  • 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-02T15:11:08+00:00Added an answer on June 2, 2026 at 3:11 pm
    #include <iostream>
    #include <string>
    #include <cstdlib>
    using namespace std;
    
    //1. loop through the string looking for ".  "
    //2. when ".  " is found, delete one of the spaces
    //3. Repeat process until ".  " is not found.  
    
    string forceSingleSpaces1 (string str) {
        size_t found(str.find(".  "));
        while (found !=string::npos){
            str.erase(found+1,1);
            found = str.find(".  ");
        }
    
        return str;
    }
    
    int main(){
    
        cout << forceSingleSpaces1("sentence1.  sentence2.  end.  ") << endl;
    
        return EXIT_SUCCESS;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often see people who write SQL like this: SELECT * from TableA LEFT
Courses for people who are being introduced to programming very often include a code
I thought direct traffic are people who type the website name or click the
This question is for people who have used trent richardson's jquery timepicker jquery before.
I know of some people who use git pull --rebase by default and others
Edit Since there were many downvotes and people who didn't understand what I'm asking
This question is for the people who know both Haskell (or any other functional
I am on a team of three people who are developing a Silverlight application.
There are many how-to's for people who want to use Rails with Apache and
I have a page which has a tree directory of people who work at

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.