WRITING A HARD PROGRAM!!

Ok
Last edited on
just google "c++ reading words from file".
i got lots of hits. that'll read them in.

storing, have a read of this:
http://www.cplusplus.com/doc/tutorial/arrays/

or this, if you're allowed to use them:
http://www.cplusplus.com/reference/vector/vector/

i would store them in a collection of std::string. (e.g.

1
2
3
4
5
 std::string words [1000];

//or

std::vector<std::string> words;


Get that bit working for now.
Last edited on
File input: http://www.learncpp.com/cpp-tutorial/136-basic-file-io/

...
see 2nd example above link, then
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
string str[1001];

cin >> str[0]; // word to be searched
int n=0;
while(inf)
{
  n++;
  inf >> str[n];
}

for(int i =1; i<=n; i++)
{
  if(str[i]==str[0])
  {
     cout << i << "th position\n";
  }
}

cout <<"Search finish\n";
Topic archived. No new replies allowed.