Sorry to bother you all with such trivial stuff, but I just finished about 35 years of work in construction, all over the US and Europe. And when the market went south I went back to school. Calc and trig are going fine, but C++ is kicking my butt. We went from “Hello World to arrays, to structs, to classes, to vectors, to pointers, to namespaces and I/O streams, and I’m still spinning. I PROMISE to only ask for help on a topic once. And for every take, I will provide a put. I don’t have a big bag of puts yet, but every time y’all help me, I get better…it’s just a matter of time until I can be as helpful to others as you’s are to me now. Thanks in advance.
For now:
What I need is a good function for taking out the white space.
I need to edit and correct a string of class string. I commented out a lot because I am temporarily lost. My main focus is to remove whitespace. I think the “toupper” and the rest will come to me fine, but I can’t get how to find, skip, and remove, or copy the corrected version to str2.
Please help.
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
//string removeSpaces(string s1, string& s2);
// void swap(char& v1, char& v2);
int main()
{
string str1(" the Answer to life, the universe and everything IS 42.");
string str2;
//cout << "Enter a sentence to be corrected\n"
// << "followed by pressing Return.\n";
//cin.getline(str1, 100);
cout << endl;
cout << " You entered: \n\n";
cout << str1 <<endl;
cout << endl;
//removeSpaces(str1[100], str2[100]);
cout << endl;
//cout << " The corrected version is: \n";
cout << str1 << endl;
//cin.getline(str2, 100);
cout << endl;
//cout << str2 << endl;
return 0;
}
/*string removeSpaces(string s1, string& s2)
{
int j = 0;
for(int i = 0; i < 100; i++)
{
if(s1[i] == ' ')
++j;
if(j > 1)
s1 = 'x';
//s2[i] = s1[i + 1];
}
return s1;
}*/
/* void swap(char& v1, char& v2)
{
char temp = v1;
v1 = v2;
v2 = temp;
}*/