Why am I getting this weird error on the scramble program

The cause of the issue was when I inserted this code:
1
2
infile >> wordlist[i];
i++;


I'm not sure why my the code will execute. Additionally, it says "no match for operator >> in infile...etc" could someone give me a clue as to what to do? I noticed changing >> to << solved a bunch of issues but I still get the no match for operator issue.
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
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

string sort(string s); // returns alphabetized version of s

struct word {
	string sorted;		// "ackrt"
	string original;	// "track"
};


int main() {
	const int maxSize = 200000;
	static word wordlist[maxSize]; // to hold the words

	int numWords; // total number of words read in from file
	ifstream infile;
	infile.open("words.txt");
	int i = 0;
	while (infile && i < maxSize) {
		// read each word into wordlist until the end of file
		// your code here
		
	infile >> wordlist[i];
	i++;
	}
	numWords = i;
	
	string w;
	do {
		bool found = false;
		cout << "Please type in a word to unscramble or 'q' to quit: ";
		// find each occurrence of wordslist[i].sorted that matches sort(w)
		// your code here.

	} while (w != "q");
					
	return 0;
}


string sort(string  s) {
//	return a string with the characters of s rearranged alphabetically.
//  For example sort("track") returns "ackrt" 
	string t;
	while (s != "") {
		int minIndex = 0;
		for (int i = 1; i< s.length(); i++) 
			if (s[i] < s[minIndex])
				minIndex = i;
		t += s[minIndex];		// add the smallest character to t
		s.erase(minIndex,1);	// remove the smallest character from s
	}
	return t;
}	

ere.
infile >> wordlist[i];
wordlist[i] is of type word. This is a type that your program created and hence something the standard library does not know how to operate on unless you tell it. I suspect that you meant
infile >> wordlist[i].original;
because the compiler does know what to do with >> and strings.

Unless you put some sort of input (i.e. use cin >>) into your loop
1
2
3
4
5
6
7
do {
		bool found = false;
		cout << "Please type in a word to unscramble or 'q' to quit: ";
		// find each occurrence of wordslist[i].sorted that matches sort(w)
		// your code here.

	} while (w != "q");

then you will whizz round and round for ever.
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/204231/
Topic archived. No new replies allowed.