Click here to Skip to main content
15,897,226 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: file manipulation with fopen(), fscanf() [modified] Pin
Zac Howland29-Jun-06 10:32
Zac Howland29-Jun-06 10:32 
GeneralRe: file manipulation with fopen(), fscanf() Pin
kitty529-Jun-06 10:55
kitty529-Jun-06 10:55 
GeneralRe: file manipulation with fopen(), fscanf() Pin
Zac Howland29-Jun-06 11:06
Zac Howland29-Jun-06 11:06 
GeneralRe: file manipulation with fopen(), fscanf() Pin
kitty529-Jun-06 11:19
kitty529-Jun-06 11:19 
GeneralRe: file manipulation with fopen(), fscanf() Pin
Zac Howland29-Jun-06 15:57
Zac Howland29-Jun-06 15:57 
QuestionRe: file manipulation with fopen(), fscanf() [modified] Pin
kitty529-Jun-06 11:55
kitty529-Jun-06 11:55 
AnswerRe: file manipulation with fopen(), fscanf() Pin
Zac Howland29-Jun-06 15:59
Zac Howland29-Jun-06 15:59 
AnswerRe: file manipulation with fopen(), fscanf() Pin
Stephen Hewitt29-Jun-06 18:01
Stephen Hewitt29-Jun-06 18:01 
Here's how I would do it:
-------------------------

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>

int main(int argc, char* argv[])
{
using namespace std;

// Open the file for reading.
ifstream ifs("C:\\a.txt");
if (!ifs)
{
cerr << "Unable to open file" << endl;
return 1;
}

// Read in the contents of the file.
typedef string type_t; // You can change the type of the data here.
typedef vector<type_t> container_t; // The collection we use to store the data we read.
container_t FileContents;
copy(
istream_iterator<type_t>(ifs), istream_iterator<type_t>(),
back_inserter(FileContents)
);

// Write the contents of the container to the console.
copy(
FileContents.begin(), FileContents.end(),
ostream_iterator<type_t>(cout, "\n")
);

return 0;
}

-------------------------

Changing a single line as follows reads and stores the data as ints instead or strings:
typedef int type_t; // You can change the type of the data here.



Steve
QuestionStatic Variables [modified] Pin
Jay0329-Jun-06 8:41
Jay0329-Jun-06 8:41 
AnswerRe: Static Variables Pin
toxcct29-Jun-06 8:58
toxcct29-Jun-06 8:58 
AnswerRe: Static Variables Pin
Jun Du29-Jun-06 8:58
Jun Du29-Jun-06 8:58 
AnswerRe: Static Variables Pin
David Crow29-Jun-06 8:58
David Crow29-Jun-06 8:58 
QuestionPrinting format of numbers Pin
mikobi29-Jun-06 7:41
mikobi29-Jun-06 7:41 
AnswerRe: Printing format of numbers Pin
David Crow29-Jun-06 8:10
David Crow29-Jun-06 8:10 
AnswerRe: Printing format of numbers Pin
Eric Dahlvang29-Jun-06 10:33
Eric Dahlvang29-Jun-06 10:33 
Questioninstallatio package creation Pin
Desmo1629-Jun-06 7:02
Desmo1629-Jun-06 7:02 
JokeRe: installatio package creation Pin
James R. Twine29-Jun-06 8:42
James R. Twine29-Jun-06 8:42 
Questionsuggestion..pls Pin
RockyJames29-Jun-06 7:01
RockyJames29-Jun-06 7:01 
AnswerRe: suggestion..pls Pin
David Crow29-Jun-06 7:02
David Crow29-Jun-06 7:02 
GeneralRe: suggestion..pls Pin
RockyJames29-Jun-06 7:53
RockyJames29-Jun-06 7:53 
GeneralRe: suggestion..pls Pin
David Crow29-Jun-06 8:09
David Crow29-Jun-06 8:09 
GeneralRe: suggestion..pls Pin
RockyJames29-Jun-06 8:20
RockyJames29-Jun-06 8:20 
AnswerRe: suggestion..pls Pin
Zac Howland29-Jun-06 7:38
Zac Howland29-Jun-06 7:38 
GeneralRe: suggestion..pls Pin
RockyJames29-Jun-06 8:36
RockyJames29-Jun-06 8:36 
GeneralRe: suggestion..pls Pin
Zac Howland29-Jun-06 9:47
Zac Howland29-Jun-06 9:47 

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.