On 8/30/07, Robert Ryan <[EMAIL PROTECTED]> wrote:
> why does this give no response
>
> #include <string>
> #include <iostream>
> #include <fstream>
> #include <vector>
> using namespace std;
>
> int main() {
> vector<string> words;
> ifstream in("GetWords.cpp");
> string word;
> while(in >> word)
> words.push_back(word);
> for(int i = 0; i < words.size(); i++)
> cout << words[i] << endl;
> } ///:~
>
Learn to always do error checking, and your life will be easier. Also,
proper indentation helps in the readibility of your program.
Here's your code, indented and checking added:
<snip includes>
int main() {
vector<string> words;
ifstream in("GetWords.cpp");
if (in) {
string word;
while(in >> word)
words.push_back(word);
for(int i = 0; i < words.size(); i++)
cout << words[i] << endl;
}
else {
cout << "Error reading file!" << endl;
}
} ///:~
--
Tamas Marki