isdigit and isalpha

My question is about the isalpha() statement. I know that the islpha is to check if it is a char but, i get errors in the for loop. How can i resolve this problem any guidance will help. Thanks in advance.



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
#include <iostream>
#include <fstream>
#include <string>

using namespace std;


int main()
{
	string line;

	ifstream inputfile;

	inputfile.open("text.txt");

	if (inputfile.is_open())
	{
		

		cout << "the file is open safely and it reads this\n\n" << endl;

		cout << line << endl;

		cout << "\n\n" << endl;

	
		while (getline(inputfile,line))
		{
			cout << "After the changes from the file it reads this" << endl;


			for (int i = line.begin(); i < line.end(); i++)
			{
				if (islower(toupper(line)))
				{
					cout << line << endl;
				}

				if (isdigit(line))
				{
					cout << "the numbers in the file are " << line << endl;
				}
			}
		}


		inputfile.close();
	}

	else
		cout << "Error file could not be read " << endl;


	system("pause");
	return 0;
}

@TheSmallGuy , TheSmallGuy

Yes it worked and as for the

 
if (islower(toupper(line)))


it is checking for the characters if the file reads it as numbers, im still looking into that part
or did i use that part wrong?
Thanks for the help.
Last edited on
Line 32: line.begin(), line.end() return iterators, not ints. Therefore, you have a type mismatch with i.

Line 34: toupper expects an int, not a std::string. toupper returns an uppercase character. islower(<uppercase-char>) will always be false.

Line 39: isdigit() expects an int, not a std::string.






Topic archived. No new replies allowed.