Compiler Error

This program is supposed to read data from a file and determine whether or not the string is a pangram. I had it working perfectly as a char array, but when I tried to switch to a string I keep getting a compiler error on line 35 that says "conversion from'std::*string' to non scalar type 'std::string' requested." Not sure what this means.

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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  #include <iostream>
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <conio.h>
#include <cctype> //for towlower() and toupper() functions
#include <cstring>
using namespace std;
void pause();
bool check(string , int &, int&, int&);

int main()
{
	string pangram[6];
  	int index,count=0, count2, missing;
  	
  	fstream dataFile;
  	dataFile.open(".\\DataFiles\\pangram.txt",ios::in);
  	 if(!dataFile.is_open())
    {
        cout<<"Unable to Process"<<endl;
        return 999;
    }
    while(!dataFile.eof() && index<200)
    {
        getline(dataFile, pangram[index],'\n');

        index++;
    }
    int maxElements = index;

	if(check(pangram, count2, missing, count))

		cout<<"The sentence is a pangram.\n\n";

	else

		cout<<"The sentence is not a pangram.\n\n";

    

    cout<<"    Alphabetic Characters: "<<count<<endl
        <<"Number of Missing Letters: "<<missing<<endl;



	return 0;
}





bool check(string pangram, int &count2, int &missing, int &count)
{
    bool flag = false;
    count2 = 0;
    missing = 0;
    count = 0;


    for (char letter = 'A'; letter <= 'Z'; letter++)
	{

        flag = false;
        for (int index = 0; index < pangram.length(); index++)
		{
           	char temp = toupper(pangram[index]);
            if (isalpha (temp))
                count++;
          	if (temp == letter)
			{
				count2++;
				flag = true;
				index = pangram.length();
            }
         }

         if(flag == false)
         {
             missing++;
             cout<<letter<<" is missing!"<<endl;
             pause();
             //cout<<letter<<endl;
         }
    }

    if (count2 == 26)

        return true;

    else

        return false;

}
void pause()
{
	do
	{
		printf("\n%s","Press any key..");
	}while(!getch());
    printf("\n\n");
	return;
}
Last edited on
At line 17 you are not initializing one string, but an array of strings. Remove the "[6]".


ps: You don't need half of those #include's.
Last edited on
Topic archived. No new replies allowed.