reading in words from a file and making an array list

i am trying to put a list of 78 words onto an array of strings so that it can be checked the program works as in it copys the input file words on the array but the array doesn't keep the words can anyone work out why?

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

using namespace std;

void main()
{
	ifstream WordList("WordList.txt");
	char str[30];
	int n = 100;
	string* words = new string[n];
	int x= 0;

	while(!WordList.eof())
	{
		WordList.getline( str, 30);
		cout << str << endl;
		words[x] == str;
		x++;
	}

	delete[] words;
		


	WordList.close();

	system("pause");
}
Try changing line 19:
words[x] == str;
which is now comparison to
words[x] = str;
which will be assignment.

Regards

P.S. There is a getline function that works directly with strings and is much safer:
http://www.cplusplus.com/reference/string/getline/

Then, you will not need the intermediate buffer in str.
Last edited on
ahhh i feel a little stupid now thanks :)
No worry. The language has beautiful consistent design, but dangerous to the extent of impracticality. Tests are permitted as statements and statements are permitted as tests. May be with the proper compiler options or static analysis tool this would at least show as warning.
my lecturer would kill me for a rookiie mistake. yeah usually i use vs2010 but my laptop died so i've had to go back to an earlier version . thanks for the help
Topic archived. No new replies allowed.