Click here to Skip to main content
15,891,431 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Is my approach feasible? C++ Pin
Christian Graus24-May-07 0:50
protectorChristian Graus24-May-07 0:50 
AnswerRe: Is my approach feasible? C++ Pin
James R. Twine24-May-07 0:51
James R. Twine24-May-07 0:51 
GeneralRe: Is my approach feasible? C++ Pin
C_Zealot24-May-07 0:52
C_Zealot24-May-07 0:52 
GeneralRe: Is my approach feasible? C++ Pin
James R. Twine24-May-07 0:57
James R. Twine24-May-07 0:57 
GeneralRe: Is my approach feasible? C++ Pin
C_Zealot24-May-07 1:24
C_Zealot24-May-07 1:24 
GeneralRe: Is my approach feasible? C++ Pin
James R. Twine24-May-07 2:12
James R. Twine24-May-07 2:12 
GeneralRe: Is my approach feasible? C++ Pin
David Crow24-May-07 3:49
David Crow24-May-07 3:49 
GeneralRe: Is my approach feasible? C++ Pin
Michael Sadlon24-May-07 13:10
Michael Sadlon24-May-07 13:10 
#include < iostream >
#include < string >
using namespace std;

ifstream in("myfile.txt", ios::in);

//only run the code if the file opened correctly
if(in.good())
{
     string strWord;

     //loop until end of file
     while(!in.eof())
     {
          //read in one word at a time
          strWord << in;

          //Do stuff with each word here
     }
}

Something like that should work for what you want to do. You can even change the ifstream to split on something other than whitespace by calling one of it's functions.

See this for more reference:
http://www.cplusplus.com/reference/iostream/ifstream/[^]


Just noticed you wanted this function prototype:

 std::string readWord(ifstream& in)
{
     string s = "";

     //only read a word if the file is good
     if(in.good())
     {
          s << in;
     }

     return s;
}

QuestionHow to Get Selected Item Position In CListControl Pin
jannathali24-May-07 0:20
jannathali24-May-07 0:20 
AnswerRe: How to Get Selected Item Position In CListControl Pin
Hamid_RT24-May-07 0:31
Hamid_RT24-May-07 0:31 
GeneralRe: How to Get Selected Item Position In CListControl Pin
jannathali24-May-07 2:39
jannathali24-May-07 2:39 
GeneralRe: How to Get Selected Item Position In CListControl Pin
Hamid_RT24-May-07 10:31
Hamid_RT24-May-07 10:31 
AnswerRe: How to Get Selected Item Position In CListControl Pin
James R. Twine24-May-07 0:53
James R. Twine24-May-07 0:53 
GeneralRe: How to Get Selected Item Position In CListControl Pin
jannathali24-May-07 1:08
jannathali24-May-07 1:08 
GeneralRe: How to Get Selected Item Position In CListControl Pin
James R. Twine24-May-07 2:13
James R. Twine24-May-07 2:13 
GeneralRe: How to Get Selected Item Position In CListControl Pin
Hamid_RT24-May-07 10:31
Hamid_RT24-May-07 10:31 
QuestionThreads Pin
Kiran Pinjala24-May-07 0:10
Kiran Pinjala24-May-07 0:10 
AnswerRe: Threads Pin
baerten24-May-07 0:20
baerten24-May-07 0:20 
GeneralRe: Threads Pin
Kiran Pinjala24-May-07 0:32
Kiran Pinjala24-May-07 0:32 
GeneralRe: Threads Pin
baerten24-May-07 1:06
baerten24-May-07 1:06 
AnswerRe: Threads Pin
Roger Stoltz24-May-07 1:46
Roger Stoltz24-May-07 1:46 
QuestionGetting file/folder properties Pin
Akin Ocal23-May-07 23:31
Akin Ocal23-May-07 23:31 
AnswerRe: Getting file/folder properties [modified] Pin
Naveen23-May-07 23:51
Naveen23-May-07 23:51 
AnswerRe: Getting file/folder properties Pin
Hamid_RT24-May-07 0:37
Hamid_RT24-May-07 0:37 
AnswerRe: Getting file/folder properties Pin
David Crow24-May-07 3:59
David Crow24-May-07 3:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.