String array and txt file

Hi guys, I need some help. I don't know how to store ONLY the words without the punctuations or other symbols from a txt file.

1
2
3
4
5
6
7
8
9
10
11
12
13
    .
    .
    .
    while (!file.eof())
    {
        file>>arr[i];

        //convert upper case letters to lower
        if(arr[i][0] >= 'A' && arr[i][0] <= 'Z')
            arr[i][0] = arr[i][0] + 32;

        i++;
    }
Last edited on
You should write a function to remove the punctuation from a string.
Also don't use eof() on the stream, it doesn't work like people expect.

1
2
3
4
5
6
7
8
9
10
11
12
string remove_punctuation(const string& s)
{
   // try first to do it yourself
}

// reading the words
string tmp;
while(file >> tmp)
{
  string s = remove_punctuation(tmp);
  // use s
}
Topic archived. No new replies allowed.