#include <iostream>
#include <fstream>
#include <string>
int main(void)
{
std::ifstream file(__FILE__);
std::string word;
while ( file >> word )
{
std::cout << word << std::endl;
}
return 0;
}
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
Just a little help ...
[php]// pulls the words out of a text stream
string get_word(istream& in)
{
char ch;
string s;
while(in.get(ch))
{
// these characters separate the words
if (ch == ' ' || ch == ',' || ch == '.' || ch == '\n' || ch == '\t')
break;
s.push_back(ch); // build the word
}
return s;
}
[/php]
vegaseat
DaniWeb's Hypocrite
5,976 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,416
steps:
1) order a large amount of coffee
2) order some pizzas
3) kickstart your brain
4) start thinking how you would solve it
5) write down your solution in words on a piece of paper
6) translate that into a flowchart and/or other diagrams
7) translate that into a functional model of your application
8) translate that into code
9) test and fix until working
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
Sure, and that's exactly how you should do it:
Create a textfile on disk.
Read in the file in your program. C(++) has full facilities for reading and writing any kind of file built right into the core language.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
thanks for all the help..the only thing i cant figure out now is how to put the actual text file in. the text is :
this is a file containing lots of
words with whitespace such as tabs and
endoflines and blanks but no
punctuation
you should be counting the
words and reversing each word before
echoing this tothescreen at the end
print the number of words in the file
is there a way for me to put this in without actually putting all this text in my code?
Select the text in your editor and save it as test.txt then read it into your program as a text file. You can separate the text into words with strtok(), setting the appropriate delimiters. It's up to your genius to spell each word in reverse.
vegaseat
DaniWeb's Hypocrite
5,976 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,416