Click here to Skip to main content
15,898,373 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Who can help me(resize a bitmap) Pin
Halawlaws28-Jul-05 20:42
Halawlaws28-Jul-05 20:42 
GeneralRe: Who can help me(resize a bitmap) Pin
Russell'29-Jul-05 0:06
Russell'29-Jul-05 0:06 
GeneralMapping views of a MMF Pin
Bob Stanneveld28-Jul-05 20:02
Bob Stanneveld28-Jul-05 20:02 
GeneralSolved. Pin
Bob Stanneveld28-Jul-05 20:46
Bob Stanneveld28-Jul-05 20:46 
Generalreading data from a data file Pin
a_david12328-Jul-05 19:34
a_david12328-Jul-05 19:34 
GeneralRe: reading data from a data file Pin
Christian Graus28-Jul-05 19:50
protectorChristian Graus28-Jul-05 19:50 
GeneralRe: reading data from a data file Pin
David Crow29-Jul-05 6:00
David Crow29-Jul-05 6:00 
GeneralRe: reading data from a data file Pin
knapak29-Jul-05 7:27
knapak29-Jul-05 7:27 
Hello David

If you think that you've got only half the answer you need... you are not the only one! Often I get very well intentioned replies but full with the assumption that we are all engineers... Anyway, here's what I use to read realtively small files. If reading the file takes more than a few minutes, the decision to use this method or any other depends on how many times during the execution of the program you have to read the file. If you only read it once, go check the scores of the latest soccer games while the computer works. If you need to read the file many times, then it is better to transform your data file into a binary file (if you need it I can also send you code for that). You'll have to wait once while the file is converted but once your data is in binary, reading it from your program is lightning fast. OK, here's the code to read a text file regardless of the file extension. Note that I made the code general so that the first header lines can be one or more. You can choose to change the cin inputs if you know in advance what the will always be (i.e. one header line). Also, please note that the data being read by this program is comma separated. If you don't have commas, use the next commented line. If your data files have a variable amount of lines (e.g. you don't always have the same amount of rows) use a vector container to store your data. Don't hesitate to ask if you have more questions.

#include <fstream>
#include <iostream>
using namespace std;

int main()<br />
{<br />
	char stuff[100];<br />
	int period, stufflines;<br />
	double dat1, dat2, dat3, dat4, integ, fraction;<br />
	char separator;<br />
	int counter;<br />
<br />
	cout << " " << endl;<br />
	cout << "how many lines with stuff at the beginning?" << endl;<br />
	cin >> stufflines;<br />
	cout << " " << endl;<br />
<br />
	ifstream FileIn("C:\\SampleData\\divedata.dat");<br />
	if(!FileIn.is_open())<br />
		cout << "Could not open the file! Check directory..." << endl;<br />
	else<br />
		cout << "You're good, input file opened!" << endl;<br />
<br />
	counter = 1;<br />
	while(!FileIn.eof())<br />
	{<br />
		if(counter <= stufflines)<br />
		        FileIn.getline (stuff, 100);<br />
		else<br />
		{<br />
			FileIn >> dat1 >> separator >> dat2 >> separator >> dat3 >><br />
                        separator >> dat4;<br />
                        // FileIn >> dat1 >> dat2 >> dat3 >> dat4;     // if no commas<br />
		}<br />
		counter++;<br />
	}<br />
	return 0;<br />
}<br />


Good luck

Carlos
GeneralRe: reading data from a data file Pin
a_david1231-Aug-05 18:00
a_david1231-Aug-05 18:00 
Generaltroubles on using scroll bar in frame Pin
firebolt7728-Jul-05 16:39
firebolt7728-Jul-05 16:39 
GeneralRe: troubles on using scroll bar in frame Pin
Christian Graus28-Jul-05 17:34
protectorChristian Graus28-Jul-05 17:34 
GeneralRe: troubles on using scroll bar in frame Pin
firebolt7728-Jul-05 18:14
firebolt7728-Jul-05 18:14 
GeneralRe: troubles on using scroll bar in frame Pin
Christian Graus28-Jul-05 18:23
protectorChristian Graus28-Jul-05 18:23 
GeneralRe: troubles on using scroll bar in frame Pin
firebolt7728-Jul-05 19:52
firebolt7728-Jul-05 19:52 
GeneralRe: troubles on using scroll bar in frame Pin
Christian Graus28-Jul-05 19:54
protectorChristian Graus28-Jul-05 19:54 
GeneralRe: troubles on using scroll bar in frame Pin
firebolt7728-Jul-05 20:06
firebolt7728-Jul-05 20:06 
GeneralRe: troubles on using scroll bar in frame Pin
Christian Graus31-Jul-05 12:59
protectorChristian Graus31-Jul-05 12:59 
GeneralRe: troubles on using scroll bar in frame Pin
firebolt7731-Jul-05 15:19
firebolt7731-Jul-05 15:19 
GeneralRe: troubles on using scroll bar in frame Pin
Christian Graus31-Jul-05 15:58
protectorChristian Graus31-Jul-05 15:58 
GeneralRe: troubles on using scroll bar in frame Pin
firebolt7731-Jul-05 16:16
firebolt7731-Jul-05 16:16 
GeneralRe: troubles on using scroll bar in frame Pin
Christian Graus31-Jul-05 16:20
protectorChristian Graus31-Jul-05 16:20 
GeneralRe: troubles on using scroll bar in frame Pin
firebolt7731-Jul-05 16:38
firebolt7731-Jul-05 16:38 
Generala very looooong integer Pin
knapak28-Jul-05 15:34
knapak28-Jul-05 15:34 
GeneralRe: a very looooong integer Pin
Christian Graus28-Jul-05 15:40
protectorChristian Graus28-Jul-05 15:40 
GeneralRe: a very looooong integer Pin
Bob Stanneveld28-Jul-05 19:14
Bob Stanneveld28-Jul-05 19:14 

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.