|
You could do something like this if you have to:
#include <fstream.h>
void main()
{
fstream infile;
char c;
int i = 0;
infile.open("data.txt", ios::in);
while(!infile.eof())
{
infile.get(c);
if(c == '\n')
i++;
}
i++;
cout << "data.txt has " << i << " lines.\n";
}
-Nick Parker
|
|
|
|
|
Or alternatively:
ifstream File;
File.open("data.txt");
int i = 0;
while ( !File.eof() )
{
File.getline(szBuffer, sizeof(szBuffer), '\n');
i++;
}
cout << "data.txt has" << i << " lines." << endl;
|
|
|
|
|
I've added a CGridCtrl to my dialog in the SDI project just like in the tutorial. I provided the name MFCGridCtrl, just like in the tutorial. However, when I go to create a member variable so I can use it, the Class Wizard won't allow me to add a member variable. Did I miss a step??
|
|
|
|
|
I think you have to do that manually...
[EDIT]
Add this to your class definition:
CGridCtrl m_Grid;
Add this after CDialog::DoDataExchange(pDX); in your DoDataExchange(CDataExchange* pDX) member function
DDX_GridControl(pDX, IDC_GRID, m_Grid);
[/EDIT]
John
|
|
|
|
|
Thanks, I tried that. I copied it from the demo project. I didn't think you could do that.
|
|
|
|
|
If I am in my CWinApp class, how do I get access to ALL documents. Reason is, I want to update all my documents when the Word Wrap option changes. Thanks!
|
|
|
|
|
You'll first need to call GetMainWnd(), then call GetActiveDocument().
|
|
|
|
|
This should do what you want:
POSITION pos = m_pDocManager->GetFirstDocTemplatePosition();
while( pos )
{
CDocTemplate* pTemplate = m_pDocManager->GetNextDocTemplate(pos);
POSITION pos2 = pTemplate->GetFirstDocPosition();
while( pos2 )
{
CDocument * pDoc = pTemplate->GetNextDoc(pos2);
if( pDoc )
pDoc->UpdateAllViews();
}
}
<pre\>
INTP
|
|
|
|
|
I have an application, and basically I just want to make it able to dock at the bottom of the screen... Its not a dialog, its simple a Win32 API CreateWindow() WS_OVERLAPPEDWINDOW window... Is there an easy way to do this?
|
|
|
|
|
|
I know this is a studid question, but I am only able to create an instance of a struct.
I actually need an instance of the struct container
I have created a struct in class RFMAccess and I'm trying to get the elements from it in another class.
<br />
struct TSimHeader<br />
{<br />
char Name[45];<br />
char Unit[45];<br />
double Min[45];<br />
double Max[45];<br />
int SignalCount;<br />
int SimStatus;<br />
<br />
}static TSimHeader_arr[10];
I can get them if I access them with the class name.
RFMAccess::TSimHeader_arr[j].Name[i];
I really don't want to have to type all of this so is there a way that I can create and instance of the container?
so I coule type s[j].Name[i]
I know, I know you guys feel like I have had the same kind of question for a week now.
Sorry, but I keep changing things around.
thanks for the help,
steven
|
|
|
|
|
No, not unless the other class was derived from RFMAccess. The statement s[j].Name[i] tries to resolve 's' to the calling class or any class it is derived from.
Even if this other class were made a friend class of RFMAccess, it still wouldn't help. This designation simply allows access to private and protected members, but you'd still have to qualify them.
|
|
|
|
|
So, your saying that I can't make and instance of the struct container?
steven
|
|
|
|
|
Saying "struct container" is redundant as a struct is a container of (different) data types.
That aside, I'm not sure what you are asking. Your RFMAccess class has a TSimHeader structure in it with 10 instances defined. In order to access any one instance, you'll need to use square brackets like you've shown. It makes no difference whether you use TSimHeader_arr[i], or s[i].
Here's a kludgy example:
class MyOtherClass
{
struct RFMAccess::TSimHeader *ts;
void foo( int x )
{
ts = &(RFMAccess::TSimHeader_arr[x]);
}
};
You could also add the following function to your RFMAccess class:
static struct TSimHeader *GetSingleInstance( int x )
{
return (&TSimHeader_arr[x]);
}
And use it in another class like:
void foo2( void )
{
struct RFMAccess::TSimHeader *ts;
ts = RFMAccess::GetSingleInstance(0);
}
Notice that qualification is still necessary for both usages.
|
|
|
|
|
OK I see what you are saying,
Thanks,
steven
|
|
|
|
|
I was reading that a function always requires a return, but I don't see one for the statement below. I've posted the entire program below also. Thanks.
(cin>>x).get();
----------------------------------------------------------
#include "iostream.h"
#include "string.h"
int main()
{
int x;
int i;
char str[80];
bool isfinished=false;
char Info [] [300] =
{
"3030-02-000-5287" , "Here is the information for this number." ,
"3030-03-000-0029" , "Here is the information for this number." ,
};
while(isfinished==false)
{
cout<<"\nPlease enter a number:\n";
cin>>str;
for(i=0; i < 4; i += 2)
if(!strcmp(str, Info[i]))
{
cout<<"\nInformation:"<<info[i+1]<<"\n";
break;
="" }
="" if(i="=" 4)
="" {
="" cout<<"number="" not="" found.\n";
=""
="" cout<<"\nwould="" you="" like="" to="" check="" another?\n";
="" cout<<"enter="" 1="" for="" yes,="" 0="" no.\n";
="" (cin="">>x).get();//no return?
}
if (x==0) isfinished=true;
}
return 0;
}
|
|
|
|
|
DaveE9th wrote:
(cin>>x).get();//no return?
It appears to be a typo (or I am wrong). It should either be:
cin >> x;
or
int x = cin.get();
-Nick Parker
|
|
|
|
|
DaveE9th wrote:
if (x==0) isfinished=true;
This is incorrect. It should be
if (x == '0') isfinished=true;
John
|
|
|
|
|
(cin>>x).get() is a confusing way of writing:
cin >> x;<br />
cin.get();
The >> opertor returns a reference to the stream, so you can call the get() method on the return value.
--Mike--
"I'm working really, really fast at the moment, so a 3 minute outage becomes, due to time dilation, a 5 minute outage."
-- Chris Maunder, relativistic system administrator
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
|
|
|
|
|
Interesting, I thought it looked like a typo.
Learn something new every day.
-Nick Parker
|
|
|
|
|
I still don't quite understand why function "get();" doesn't need a return. Why is this?
Thanks, Dave
|
|
|
|
|
The get() function with no parameters reads and returns the next character from the stream. If this character is not required (eg. you simply need to skip to the next character) then there is no use for the return value.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I read that if a function did not return a value that (at a minimum) you had to use the "void" prototype...such as below:
void main( )
no?
hmmmmm
Dave
|
|
|
|
|
The get() function returns a value - the value of the next character read. This program simply doesn't use the returned value.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Thanks Ryan
"The man who reads nothing is better educated than the man who reads nothing but
newspapers."- Thomas Jefferson
|
|
|
|