How to read file without missing the space

like in a file i got a line which is "Ali Baba" and my code will read only the word,become "AliBaba",how can i read the space also?

this is my code for load()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
oid List::load( string fileName ) throw( ListException )
{
   ifstream inFile( fileName.c_str() );
   ListItemType nextItem;
   ListNode *tail;

   while (!isEmpty())
   {
      remove( 1 );
   }
   size = 0;
    if (inFile >>nextItem)
    {
        try
        {
            head = new ListNode;
            //Add the first char to the list
            head->item = nextItem;
            head->next = NULL;
            tail = head;
            size = size+1;
            //Add remaining integers to linked list
            while( inFile >>nextItem)
            {
                tail->next = new ListNode;
                tail = tail->next;
                tail->item = nextItem;
                tail->next = NULL;
                size = size+1;
            }
        }
        catch(...)
        {
            throw ListException("ListException: restore cannot allocate memory.");
        }//end try
    }//end if

   inFile.close();
}


I hope someone can help me.
Are you reading line by line or word by word?
word by word
Actually, my phrasing was wrong.

Anyway, just do this:
std::string line
std::getline(inFile,line);
That will read the whole line.
but my teacher wan word by word one...not read whole line...
do you have to use the insertion and extrction-operators ('<<', '>>')? or may u use put,get etc, also?... i´d suggest you to use infile.get() then or something equivalent...
Last edited on
Thank you,i have solve the problem.
Topic archived. No new replies allowed.