Click here to Skip to main content
15,911,503 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Multithreading... Pin
Christian Graus8-Feb-02 16:59
protectorChristian Graus8-Feb-02 16:59 
GeneralRe: Multithreading... Pin
Brian van der Beek9-Feb-02 0:47
Brian van der Beek9-Feb-02 0:47 
GeneralCClientDC Pin
Mazdak8-Feb-02 9:49
Mazdak8-Feb-02 9:49 
GeneralRe: CClientDC Pin
8-Feb-02 9:54
suss8-Feb-02 9:54 
GeneralFile i/o Pin
8-Feb-02 8:54
suss8-Feb-02 8:54 
GeneralRe: File i/o Pin
lucy8-Feb-02 8:54
lucy8-Feb-02 8:54 
GeneralRe: File i/o Pin
Chris Losinger8-Feb-02 9:02
professionalChris Losinger8-Feb-02 9:02 
GeneralRe: File i/o Pin
Christian Graus8-Feb-02 9:06
protectorChristian Graus8-Feb-02 9:06 
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <sstream>

using std::copy;
using std::vector;
using std::string;
using std::ifstream;
using std::ostream_iterator;
using std::cout;
using std::back_inserter;
using std::getline;

using std::ostringstream;
using std::istream_iterator;

int main(int argc, char* argv[])
{
string currentLine;

ifstream str("c:\\winzip.log");
if (!str.is_open())
{
cout << "It's stuffed\n";
return -1;
}

vector<string> file_contents;

copy(istream_iterator<string>(str),istream_iterator<string>(), back_inserter(file_contents));

// Now print out the results
copy(file_contents.begin(), file_contents.end(), ostream_iterator<string>(cout, "\n"));

return 0;
}

This example reads a file in and prints the output to the console. However, the pertinent point is that you can create an fstream, which is bidirectional, or just an ifstream or ofstream, and then if you know the file format, you can, for example, do this:

myFile >> nMyNumber >> szMyString >> etc.



Christian

I have come to clean zee pooollll. - Michael Martin Dec 30, 2001

Picture the daffodil. And while you do that, I'll be over here going through your stuff.

GeneralRe: File i/o Pin
Nemanja Trifunovic8-Feb-02 9:32
Nemanja Trifunovic8-Feb-02 9:32 
GeneralRe: File i/o Pin
8-Feb-02 9:36
suss8-Feb-02 9:36 
GeneralRe: File i/o Pin
Christian Graus8-Feb-02 9:32
protectorChristian Graus8-Feb-02 9:32 
GeneralRe: File i/o Pin
8-Feb-02 9:38
suss8-Feb-02 9:38 
GeneralRe: File i/o Pin
Nish Nishant8-Feb-02 13:15
sitebuilderNish Nishant8-Feb-02 13:15 
GeneralRe: File i/o Pin
Christian Graus8-Feb-02 9:32
protectorChristian Graus8-Feb-02 9:32 
GeneralRe: File i/o Pin
Nemanja Trifunovic8-Feb-02 9:42
Nemanja Trifunovic8-Feb-02 9:42 
GeneralRe: File i/o Pin
Christian Graus8-Feb-02 9:46
protectorChristian Graus8-Feb-02 9:46 
GeneralRe: File i/o Pin
Nish Nishant8-Feb-02 13:22
sitebuilderNish Nishant8-Feb-02 13:22 
GeneralRe: File i/o Pin
Christian Graus8-Feb-02 13:42
protectorChristian Graus8-Feb-02 13:42 
GeneralRe: File i/o Pin
Sprudling8-Feb-02 9:54
Sprudling8-Feb-02 9:54 
GeneralRe: File i/o Pin
Christian Graus8-Feb-02 13:43
protectorChristian Graus8-Feb-02 13:43 
GeneralRe: File i/o Pin
Tim Smith8-Feb-02 17:42
Tim Smith8-Feb-02 17:42 
GeneralRe: File i/o Pin
Christian Graus8-Feb-02 17:49
protectorChristian Graus8-Feb-02 17:49 
GeneralRe: File i/o Pin
Sprudling8-Feb-02 22:31
Sprudling8-Feb-02 22:31 
GeneralRe: File i/o Pin
Christian Graus8-Feb-02 22:42
protectorChristian Graus8-Feb-02 22:42 
GeneralRe: File i/o Pin
8-Feb-02 10:53
suss8-Feb-02 10:53 

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.