|
There are many ways to approach this. One, although not the most efficient, looks something like:
FILE *pFile;
int XLOC, YLOC, INDIX;
char szLine[128];
pFile = fopen("filename.dat", "rt");
fgets(szLine, sizeof(szLine), pFile);
fgets(szLine, sizeof(szLine), pFile);
fgets(szLine, sizeof(szLine), pFile);
fgets(szLine, sizeof(szLine), pFile);
fgets(szLine, sizeof(szLine), pFile);
fgets(szLine, sizeof(szLine), pFile);
while (! feof(pFile))
fscanf(pFile, "%d %d %d", &XLOC, &YLOC, &INDIX);
fclose(pFile); A similar MFC solution exists.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
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 />
}<br />
counter++;<br />
}<br />
return 0;<br />
}<br />
Good luck
Carlos
|
|
|
|
|
|
hi all..I want to make a dialog that can be resize with HScroll and VScroll. But when I tried the program, the dialog window can be resized, but the scroll doesn't work(I added the scroll using class wizard by right-clicking the dialog window, go to properties, and checked horizontal scroll and vertical scroll). Pls help...
thx.
|
|
|
|
|
Scroll doesn't work by itself, you need to catch the scroll events, and make sure your code adjusts it's display accordingly. You also need to set the range of the scroll bars.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
how to implement it? Can u give some tutorials,articles,or some link that can be helpful..pls
thx
|
|
|
|
|
What version of VC are you using ? Whatever it is, you can set an event handler for each of the two scroll events ( but if I know which one, I can tell you exactly where ), and then you force a redraw with Invalidate(), and your drawing code takes the scroll position into account. I don't know of any tutorials, off hand, sorry. I'd be surprised if this site didn't have any.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I'm using VC 6.0. I already make the event handler. On where I should write my drawing code? Btw...what is the keyword for finding thw tutorials(I try "repainting window" keyword, but I didn't find any suitable articles)
thx...
|
|
|
|
|
firebolt77 wrote:
On where I should write my drawing code
Drawing code is ALWAYS in OnPaint. Invalidate(); is all the code you need to put in a scroll event to force a repaint.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thx...but I'm still confuse on the drawing code
I'm still new in MFC so I'm still lack of knowledge in MFC
thx anyway..
|
|
|
|
|
Well, what are you drawing ? How do you draw it now ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
just ordinary dialog box with tab control, tree control, button, edit box, etc. I want the dialog box can be resize to smaller size, and I can use the scroll bar to see all of the frame. Sorry for the bad english...but I hope you understand what I mean
thx..
|
|
|
|
|
Oh, OK. Well, I'd have thought a CFormView would handle that by itself. There's no painting involved here - your controls all need to be on some sort of control that you can position, otherwise you need to call SetWindowPos on all of them to move them, which is kind of ugly.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
hmm..but I'm using CDialog base class. Can I use the method?
thx..
|
|
|
|
|
Yeah, I guessed that. You need to do what I said as an alternative, get a blank control ( that is, one that gives you a surface, but nothing on it, probably the control base class ), set out all your controls on that, and move it's location using SetWindowPos in response to the scroll bars. So the scroll range for X is the width of your control - the width of the window, and the same for the Y. Then when your scroll event occurs, you set the window position of the control to be the offset of the scroll pos, so if hte X scrollbar is set to 20, then the X position is -20, so the first twenty pixels of the control are to the left of the left edge of the main window.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
Hi geeks... I mean guys guys...
I need to use a very large integer that does not fit in a long. So I attempted using _int64 and the values are at least stored in the declared variable. However if I try to send it to the screen, it gives me this compiler error...
error C2593: 'operator <<' is ambiguous
Can anyone give me a simple explanation and solution? Is there any other place I need to be aware of where I'll run into trouble if using this data type?
Thanks a bunch!!!
|
|
|
|
|
knapak wrote:
error C2593: 'operator <<' is ambiguous
operator << is not defined for __int64. Therefore it has to try and cast it to something else ( which is plainly not going to work BTW ), and it can't decide what it should cast it to, hence the operator is ambiguous. You probably have to define your own operator <<, and I guess then any other STL operation you try to do, that is type specific.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hello,
The __int64 is not supported by the standard, but it is rather compiler specific. The C standard has support for a 64 bit integer: long long . See here[^] for more information.
You always can write the number in hexadecimal in two steps: first write the upper 32 bits and then the lower 32 bits.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Hello all.
As an assignment, I'm trying to design front end for a database prepared in Ms Access using Visual C++. I'm using ODBC.
I'm designing an SDI Application with Multiple Views. The parent view is "Employee" and the child view is details about "core Staff members", if an employee is a Core staff member, clicking the button for "Core Staff" takes you to another view, with details regarding the employee. This child view has a button which takes you back to the parent view, say "Employee View".
Now, the problem is that when I click the "Core Staff" button, I get the new view if the current employee is a core staff member, but the problem is that the new view is "un-clickable" I cant click anything, If I try clicking something the window freezes on me. I can however navigate through the fields using the tab key, or the short cut keys. However, when I select the "EMployee View" button and press enter, I get the message for Invalid View ID, which is supposed to be displayed if the "View doesnt exist".
Here's the code for the "SelectView" function in the CMainFrame class.
[code]
void CMainFrame::SelectView(UINT ViewID)
{
CView* pOldActiveView = GetActiveView();
CView* pNewActiveView = (CView*)GetDlgItem(ViewID);
if(pNewActiveView == NULL)
{
switch(ViewID)
{
case CORE_VIEW:
pNewActiveView = (CView*)new CCoreView;
break;
default:
AfxMessageBox("Invalid View ID");
return;
}
CCreateContext context;
context.m_pCurrentDoc = pOldActiveView->GetDocument();
pNewActiveView->Create(NULL, NULL, 0L, CFrameWnd::rectDefault,this,ViewID,&context);
pNewActiveView->OnInitialUpdate();
}
if(ViewID == CORE_VIEW && ! ((CCoreView*)pNewActiveView)->IsCore())
{
AfxMessageBox("Current Employee is not a Core Staff Member");
return;
}
SetActiveView(pNewActiveView);
pOldActiveView->ShowWindow(SW_HIDE);
pNewActiveView->ShowWindow(SW_SHOW);
pOldActiveView->SetDlgCtrlID(m_CurrentViewID);
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
m_CurrentViewID = ViewID;
RecalcLayout();
}
[/code]
The code for the Button on the "Employee View" is:
[code]
((CMainFrame*)GetParentFrame())->SelectView(CORE_VIEW);
[/code]
Similarly, the code for the button on the "Core VIew" is:
[code]
((CMainFrame*)GetParentFrame())->SelectView(EMPLOYEE_VIEW);
[/code]
I'm following "Ivor Horton's" "Beginning Visual C++6". Since, the "Parent View" alread exists, GetDlgItem() should return the address of the view, otherwise return Null.
I dont know whats wrong here.
Can anyone please help?
Thanks
and here are the screenies.
EMPLOYEE VIEW
[img]http://img196.imageshack.us/img196/282/employee9ps.jpg[/img]
CORE VIEW
[img]http://img211.imageshack.us/img211/7392/core5nq.jpg[/img]
Thanks again.
|
|
|
|
|
Say i have a client and server. Server listening at 10.10.10.10 on port 4000. Client connects from 11.11.11.11. Server sends back a message saying:
"You are connected from <ip> on port <port>"
Where having the server use GetPeerName would give the proper ip of 11.11.11.11, but the port will be some other number other than 4000 in my case. So the message to the client would say something like:
"You are connected from 11.11.11.11 on port 3000"
Should GetPeerName be returning 4000 as the port? Or is the port of the client just a random one?
|
|
|
|
|
Type: netstat -n
GetPeerName will return the "remote address" column (only a single item of course).
Don't try it, just do it!
|
|
|
|
|
Ok thanks. The client port is just a random one. I get it now.
|
|
|
|
|
I am starting a project soon and the contact wants to control the record volume settings from within the application. Is there a way to do this with sndvol32 or some other way without using DirectX? He is concerned about file size, that's why he doesn't wish to use DirectX. Thanks.
Bill Dennis
Orlando, FL
|
|
|
|
|
billiam904 wrote:
He is concerned about file size
Using DirectX does not create big binaries at all!
By the way: DirectX does adjust the volume of a single buffer, but not the volume of the system. You can use waveOutSetVolume to set the output volume.
Don't try it, just do it!
|
|
|
|
|