Click here to Skip to main content
15,894,646 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: ifstream question Pin
etm12425-Apr-06 14:09
etm12425-Apr-06 14:09 
GeneralRe: ifstream question Pin
etm12425-Apr-06 14:13
etm12425-Apr-06 14:13 
GeneralRe: ifstream question Pin
Stephen Hewitt25-Apr-06 14:20
Stephen Hewitt25-Apr-06 14:20 
GeneralRe: ifstream question Pin
etm12425-Apr-06 14:22
etm12425-Apr-06 14:22 
GeneralRe: ifstream question Pin
Stephen Hewitt25-Apr-06 14:26
Stephen Hewitt25-Apr-06 14:26 
GeneralRe: ifstream question Pin
etm12425-Apr-06 14:28
etm12425-Apr-06 14:28 
GeneralRe: ifstream question Pin
etm12425-Apr-06 14:36
etm12425-Apr-06 14:36 
GeneralRe: ifstream question Pin
Stephen Hewitt25-Apr-06 14:47
Stephen Hewitt25-Apr-06 14:47 
There are problems with this code: you have 2 variables called "p1" and 2 called "p2".
Anyway here how I'd read in a list of points:
----

// Console.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
using namespace std;

// Our point structure.
class My3DPoint
{
public:
My3DPoint() : x(0), y(0), z(0) {}
My3DPoint(int _x, int _y, int _z) : x(_x), y(_y), z(_z) {}
int x, y, z;
};

// A collection of "My3DPoint"s.
typedef vector<My3DPoint> My3DPoints;

int main(int argc, char* argv[])
{
ifstream in("C:\\a.txt");

My3DPoints points;

string label;
int x, y, z;
while (in >> label >> x >> y >> z)
{
points.push_back(My3DPoint(x, y, z)); // Add it to our collection.
}

// Now print the collection (in reverse order for fun):
typedef My3DPoints::reverse_iterator RI; // To save some typing.
for ( RI i=points.rbegin(); i!=points.rend(); ++i )
{
const My3DPoint &pt = *i;
cout << "(" << pt.x << ", " << pt.y << ", " << pt.z << ")\n";
}

return 0;
}


Steve
GeneralRe: ifstream question Pin
etm12425-Apr-06 14:55
etm12425-Apr-06 14:55 
QuestionFavorites Icon using IWebBrowser2 control Pin
achimera25-Apr-06 13:08
achimera25-Apr-06 13:08 
AnswerRe: Favorites Icon using IWebBrowser2 control [modified] Pin
code-frog25-Apr-06 17:09
professionalcode-frog25-Apr-06 17:09 
GeneralRe: Favorites Icon using IWebBrowser2 control Pin
achimera25-Apr-06 17:32
achimera25-Apr-06 17:32 
GeneralRe: Favorites Icon using IWebBrowser2 control Pin
code-frog25-Apr-06 17:41
professionalcode-frog25-Apr-06 17:41 
GeneralRe: Favorites Icon using IWebBrowser2 control Pin
achimera25-Apr-06 18:05
achimera25-Apr-06 18:05 
GeneralRe: Favorites Icon using IWebBrowser2 control Pin
code-frog25-Apr-06 18:13
professionalcode-frog25-Apr-06 18:13 
GeneralRe: Favorites Icon using IWebBrowser2 control Pin
Russell Morris25-Apr-06 18:08
Russell Morris25-Apr-06 18:08 
GeneralRe: Favorites Icon using IWebBrowser2 control Pin
achimera25-Apr-06 18:13
achimera25-Apr-06 18:13 
AnswerRe: Favorites Icon using IWebBrowser2 control Pin
Mike Dimmick26-Apr-06 2:22
Mike Dimmick26-Apr-06 2:22 
GeneralRe: Favorites Icon using IWebBrowser2 control Pin
achimera26-Apr-06 9:44
achimera26-Apr-06 9:44 
Questionbit shifting Pin
Waldermort25-Apr-06 11:46
Waldermort25-Apr-06 11:46 
AnswerRe: bit shifting Pin
Michael Dunn25-Apr-06 12:58
sitebuilderMichael Dunn25-Apr-06 12:58 
GeneralRe: bit shifting Pin
Waldermort25-Apr-06 19:51
Waldermort25-Apr-06 19:51 
GeneralRe: bit shifting Pin
Michael Dunn25-Apr-06 20:41
sitebuilderMichael Dunn25-Apr-06 20:41 
GeneralRe: bit shifting Pin
Waldermort25-Apr-06 20:43
Waldermort25-Apr-06 20:43 
AnswerRe: bit shifting Pin
Bob Flynn26-Apr-06 2:38
Bob Flynn26-Apr-06 2:38 

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.