<fstream.h> or <fstream> 
Author Message
 <fstream.h> or <fstream>

I am writing a method to read a comma delimeted text file.
The environment is in a project that was developed using the ocx class
wizard from Visual Studio 6.0

I tried the following:

#include <fstream.h>  in the Cntrl Class.

ifstream f("c:\temp\test.txt");
f.get(buffer, 256, ',');

This didn't return the results I expected.  Am I doing something wrong?
When including include files  are they to be included in stdafx.h or in the
class that uses them?



Sat, 28 May 2005 21:11:56 GMT  
 <fstream.h> or <fstream>
Here is the exact code from an MFC Console application.

  char buffer[256];
  ifstream f("c:\\temp\\test.txt");
  int i=0;
  if (f.is_open())
  {
   while (f.eof() == false)
   {
    f.get(buffer, 256, ',');
    cout << buffer << endl;
   }
   f.close();
  } else {
   cout << "Error opening file." << endl;
  }

test.txt
This,is,a,test
of,the,work,done

Output:
This

Then it hangs.
#include <fstream> in stdafx.h



Sat, 28 May 2005 22:25:09 GMT  
 <fstream.h> or <fstream>
Try this:
in the .cpp file
#include <string>
#include <fstream>
#include <iostream>
............
 ifstream ifs("c:\\temp\\test.txt");
 string strText("");
 while(ifs)
 {
  getline(ifs, strText, ',');
  cout << strText << endl;
 }
...............


Quote:
> Here is the exact code from an MFC Console application.

>   char buffer[256];
>   ifstream f("c:\\temp\\test.txt");
>   int i=0;
>   if (f.is_open())
>   {
>    while (f.eof() == false)
>    {
>     f.get(buffer, 256, ',');
>     cout << buffer << endl;
>    }
>    f.close();
>   } else {
>    cout << "Error opening file." << endl;
>   }

> test.txt
> This,is,a,test
> of,the,work,done

> Output:
> This

> Then it hangs.
> #include <fstream> in stdafx.h



Sat, 28 May 2005 23:23:39 GMT  
 <fstream.h> or <fstream>
What does one do at the end of a line? There is an implied delimiter....
TIA
Quote:

> Try this:
> in the .cpp file
> #include <string>
> #include <fstream>
> #include <iostream>
> ............
>  ifstream ifs("c:\\temp\\test.txt");
>  string strText("");
>  while(ifs)
>  {
>   getline(ifs, strText, ',');
>   cout << strText << endl;
>  }
> ...............



> > Here is the exact code from an MFC Console application.

> >   char buffer[256];
> >   ifstream f("c:\\temp\\test.txt");
> >   int i=0;
> >   if (f.is_open())
> >   {
> >    while (f.eof() == false)
> >    {
> >     f.get(buffer, 256, ',');
> >     cout << buffer << endl;
> >    }
> >    f.close();
> >   } else {
> >    cout << "Error opening file." << endl;
> >   }

> > test.txt
> > This,is,a,test
> > of,the,work,done

> > Output:
> > This

> > Then it hangs.
> > #include <fstream> in stdafx.h



Sat, 28 May 2005 23:51:14 GMT  
 <fstream.h> or <fstream>
You should use <fstream> since that is what the Standard says!

Now, the fstream stuff lives in namespace std!
So:
#include <fstream>

and then:
using namespace std;

or say:
std::ifstream f("c:\temp\test.txt");

/Ole

Quote:

> I am writing a method to read a comma delimeted text file.
> The environment is in a project that was developed using the ocx class
> wizard from Visual Studio 6.0

> I tried the following:

> #include <fstream.h>  in the Cntrl Class.

> ifstream f("c:\temp\test.txt");
> f.get(buffer, 256, ',');

> This didn't return the results I expected.  Am I doing something wrong?
> When including include files  are they to be included in stdafx.h or in
the
> class that uses them?



Sun, 29 May 2005 09:22:44 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. pb with replacing <fstream.h> by <fstream>

2. <fstream.h> and <fstream> chaos

3. <<<<<<<Parsing help, please>>>>>>>>

4. File Format conversion, ascii freeform -->.csv <-->.wk1<-->dbf<-->?HELP

5. <<<>>>Need C code advice with functions and sorting.<<<>>>

6. <><><>HELP<><><> PCMCIA Motorola Montana 33.6

7. #include <fstream> or <fstream.h>?

8. <fstream> vs <fstream.h>

9. >>>Windows Service<<<

10. <fstream>

11. <fstream> and file sharing

12. proposal: <basic.h>, <pascal.h>, <fortran.h>, <cobol.h>

 

 
Powered by phpBB® Forum Software