and this is my code How can I write code for words from the file are read into an array of strings, one word per string.?
Hello I try to write the code but it only displays the first line
for example my txt file has 100 line and one word per line
word1
word2
word3
and this is my code
How can I write code for words from the file are read into an array of strings, one word per string.?
1 2 3 4 5 6 7 8 9 10 11
|
string filewords=100;
for (int i=0;i<=99;i++)
{
inData>>filewords[i];
cout<<filewords[i];
please help... !!
i++;
}
|
First you need to declare your array properly -
string filewords[100];
Then you need to open your file and check that it opened properly.
1 2 3 4 5 6
|
ifstream inData("Filename");
if (!inData)
{
cout << "File error...";
exit(1);
}
|
Finally you can read it:
1 2 3 4 5
|
int line = 0;
while(inData && line < 100)
{
inData >> filewords[i];
}
|
thanks ^^ :)
Topic archived. No new replies allowed.