Unused Character

Nov 9, 2014 at 2:44am
Upon compilation I get a warning saying that "variable ‘z’ set but not used". How do I fix this?

1
2
3
4
5
6
7
8
9
10
11
12
  void num_chars(vector<string> words)
{
    ifstream fin(words[1]);
    char z = fin.get();
    int char_count = 0;
    while (!fin.eof())
    {
        ++char_count;
        z = fin.get();
    }
    cout << words[1] << " contains " << char_count << " characters. \n\n";
}
Nov 9, 2014 at 3:36am
Why are you initializing z as fin.get() and then assigning it to fin.get() again, inside the while loop?

Also, is there any way we can get the rest of your program? It makes troubleshooting monumentally easier.
Last edited on Nov 9, 2014 at 3:38am
Topic archived. No new replies allowed.