Removing specific letters and numbers out of a string

I am having a hard time figuring out how to remove specific things out of a string file I am working with. My assignment is to remove all numbers, periods, commas, duplicate words, "'s" and change every word to lowercase. I believe I have done everything except the lowercase part. I am getting an error currently with what I have tried to write. Here is the paragraph I have to sort:


GDP is commonly used as an indicator of the economic health of a country, as well as a gauge of a countrys standard of living. Since the mode of measuring GDP is uniform from country to country, GDP can be used to compare the productivity of various countries with a high degree of accuracy. Adjusting for inflation from year to year allows for the seamless comparison of current GDP measurements with measurements from previous years or quarters. In this way, a nations GDP from any period can be measured as a percentage relative to previous years or quarters. When measured in this way, GDP can be tracked over long spans of time and used in measuring a nations economic growth or decline, as well as in determining if an economy is in recession. GDPs popularity as an economic indicator in part stems from its measuring of value added through economic processes. For example, when a ship is built, GDP does not reflect the total value of the completed ship, but rather the difference in values of the completed ship and of the materials used in its construction. Measuring total value instead of value added would greatly reduce GDPs functionality as an indicator of progress or decline, specifically within individual industries and sectors. Proponents of the use of GDP as an economic measure tout its ability to be broken down in this way and thereby serve as an indicator of the failure or success of economic policy as well. For example, from 2004 to 2014 Frances GDP increased by 53.1%, while Japans increased by 6.9% during the same period.


Here is my current code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  #include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <algorithm>
using namespace std;

const int SIZE = 268;


struct  WordCount
{
	string name;
	int count;
};

void bubbleSort(string arr[], int size)
{
	for (int stopMarker = 1; stopMarker < size; stopMarker++)
	{
		for (int j = size - 1; j >= stopMarker; j--)
		{
			if (arr[j] < arr[j - 1])
			{
				swap(arr[j], arr[j - 1]);
			}
		}
	}
}

int main()
{
	string result;
	string wordArray[SIZE];
	WordCount arr[SIZE];
	WordCount item;

	ifstream input;

	input.open("E:\\gdp.txt");



	for (int i = 0; i < SIZE; i++)
	{
		input >> wordArray[i];
		wordArray[i].erase(remove_if(wordArray[i].begin(), wordArray[i].end(), [](char c)
		{
			return c == ',' || c == '.' ||
				c == 's' || c == 'U.S.' || c == 'A' || c == 'I' ||
				   c == '%' || c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '9';
		}),
			wordArray[i].end());


		/*if (isupper(wordArray[i]))
		{
			result += tolower(wordArray[i]);
		}*/
	}

	input.close();

	bubbleSort(wordArray, SIZE);

	int j = 0;
	for (int i = 0; j < SIZE; i++)
	{
		if (item.name != wordArray[j] && j < SIZE)
		{
			item.name = wordArray[j];
			item.count = 1;
			arr[i] = item;
			j = j + 1;
		}
		while (j < SIZE && item.name == wordArray[j])
		{
			item.count++;
			arr[i] = item;
			j = j + 1;
		}
	}

	cout << "Array content..." << endl << endl;

	for (int i = 0; i < 135; i++)
	{
		cout << setw(13) << left << arr[i].name << setw(10) << "Count = " << arr[i].count << endl;
	}

	return 0;
}
I am getting an error currently with what I have tried to write.

What is the error you're encountering?

Look at this snippet: c == 'U.S.', remember that a character constant can only contain one character.


I am not getting an error, but my code I have blocked out in green is what I am trying to fix. If I unblock it, it will give me an error. The error is saying it can't convert a string to an integer.
The error message is correct, did you find and read the documentation for the tolower() function?

Is allowable parameter a std::string?

(Hint: No, it requires a single character.)


I'm still a little confused as to what the answer you gave me means.
Also, how would I get rid of apostrophe's in the whole string?
Topic archived. No new replies allowed.