|
Your writing and reading where ok, as long as you read and wrote the same way. It would just mean that if some one else was going to read or write to the file, you would have to have documented the actual size of the record.
Whoops! getFileSize()
After calling end = tempFile->tellg(); , you need to call tempFile->seekg(0, ios::beg); . If you do not, then you will be trying to read from the end of the file. That is tellg will return -1.
You have the right idea for a general purpose function for getting the size, but I would probably do something like this:
long getFileSize(fstream * tempFile)
{
long begin, end;
begin = tempFile->tellg();
tempFile->seekg (0, ios::end);
end = tempFile->tellg();
tempFile->seekg (begin);
return end;
}
INTP
Every thing is relative...
|
|
|
|
|
|
Hi,
As in C++ , double matrix[10][10]; two dimensional array...How can we use CArray as a two dimensional..? IF we can how Can we add eleents in to this two array?.
Thanks before..
|
|
|
|
|
typedef CArray <int, int> CIntArray;
typedef CArray <CIntArray, CIntArray&> CMultiIntArray;
void TraceDynamicArray(const unsigned int rows, const unsigned int columns)
{
CMultiIntArray aTest;
aTest.SetSize( rows );
for (int row = 0; row < aTest.GetSize(); row++)
{
aTest[row].SetSize( columns );
for (int column = 0; column < aTest[row].GetSize(); column++)
{
aTest [row] [column] = 10 * row + column;
afxDump << aTest [row] [column] << "\t";
}
afxDump << "\n";
}
}
Kevin
|
|
|
|
|
I am new to MFC...As we do in C++
double matrix[10][5];
double somedoubleValue=10.005;
for(int i=0;i<10;i++)
{
for(int j=0;i<5;j++)
{
matrix[i][j]=i*j*somedoubleValue;
}
In the same manner instead i want to use CArray..bec..the Array matrix size can increase in future and i want insert in between..so i want to CArray as two dimesional array......Can we more Clear..I have read above posted message..but i don`t how to use it....so pls can be more clear.
Thank q
James
|
|
|
|
|
Try this:
CArray<CArray<int>> array;
array.SetSize(number_of_rows);
for (int row = 0; row < number_of_rows; row++) {
array[row].SetSize(number_of_columns);
}
for (int row = 0; row < array.GetSize(); row++) {
for (int col = 0; col < array[row].GetSize(); col++) {
array[row][col] = 0;
}
} This creates a two-dimensional array that is dimensioned [number_of_rows,number_of_columns] . Note that each row can be sized differently if necessary.
Software Zen: delete this;
|
|
|
|
|
I'm trying to create an AddIn for VC++ 7.1, and I'm having problems inserting a submenu into the Tools menu.
I'm also not sure how to undo the installation, so that when you look at AddIn manager, the AddIn is no longer listed.
How do I add a submenu, and how do I remove the AddIn to VC++ 7.1?
I have the following source code:
http://code.axter.com/Connect.cpp
And the current code is in the CConnect::OnConnection method.
I'm only interested in C++ methods, and not any VB code.
Thank you
Top ten member of C++ Expert Exchange.
http://www.experts-exchange.com/Cplusplus
|
|
|
|
|
Hello everyone!
I'm doing a program to learn how to use binary files...
I have a struct that has one member of type std::string and one int. I want to write that struct to a binary file, but just the int gets written!
fstream dat_file(file.c_str(), ios::out | ios::binary);<br />
<br />
Person person;<br />
<br />
person.FullName = fullName;
person.Age = atoi(strAge.c_str());<br />
<br />
dat_file.write((char*) &person, sizeof(Person));<br />
<br />
dat_file.close();
Why won't it write the name to the file? Thanks!
Lord Kixdemp
www.SulfurMidis.com
www.SulfurSoft.tk
[ftp://][http://][hotline://]tsfc.ath.cx
|
|
|
|
|
|
|
|
|
|
Morning All !
Well here is a problem. I am developing an application that needs to connect to the internet to perform an FTP transfer. Detecting the presence of a valid connection seems to be **** HARD !
Having read what’s seems to be available on developer sites, I feel the RasEnumConnections & RasGetConnectStatus have short comings and are too unreliable. (Worth pointing out that I have no experience of socket level programming)
A solution posted by Patrick Philippot seems to be what I need except the <iphlpapi.h> and lib are required and I spent many hours failing to install the SDK from Microsoft
Does anyone know of a way of detecting a valid Internet connection that wont invoke a 'dial up connection box' .
Many thanks boys and girls
Regards Philip....
|
|
|
|
|
Healdp wrote: Detecting the presence of a valid connection seems to be **** HARD !
Yup
Check out this article[^] for some ideas on how to tackle this problem.
The two most common elements in the universe are Hydrogen and stupidity. - Harlan Ellison
Awasu 2.2 [^]: A free RSS/Atom feed reader with support for Code Project.
|
|
|
|
|
Checking the routing table for a default route is the best technique I've come across so far as it does not require checking a URL, pinging an IP address, or other techniques that will not be entirely accurate in all contexts. It also does not invoke any RAS connection dialog boxes which makes it sound like what your looking for.
(You mentioned you cannot get the SDK installed. If you are using VC++ 6.0, you will need the February 2003 SDK or prior installed to use this or to at least get the header and .lib files. Any SDK after this is incompatible with VC++ 6.0 at least without jumping through numerous hoops to get it to work. If you are using VC++ 7.1, the SDK is available on your installation disks)
I got the idea from someone on CodeGuru before they upgraded their website and lost all the legacy comments. Unfortunately, I do not know the name of the person who passed on the idea so I can't give credit where credit is do but I'll pass it on...
The function to use is GetIpForwardTable(). I use a timer to periodically check for connectivity and update my status indicator accordingly. There is a slight delay maybe a second or two if you unplug the cable or plug it in (assuming your timer is set to fire every second). No noticeable delay when disabling the connection using a GUI tool.
Don't forget to include in StdAfx.h...
#include <iphlpapi.h> // For Routing table query
And make sure to reference the Platform SDK lib file...
iphlpapi.lib
BOOL CNetworkConnectionDlg::IsInternetAvailable(void)
{
MIB_IPFORWARDTABLE * pRoutingTable;
DWORD dwBufferSize=0;
BOOL bIsInternetAvailable=FALSE;
DWORD dwResult;
DWORD dwIndex;
DWORD dwRowCount;
// Get the required buffer size
GetIpForwardTable(NULL,&dwBufferSize,FALSE);
pRoutingTable=(MIB_IPFORWARDTABLE*)new BYTE[dwBufferSize];
// Attempt to fill buffer with routing table information
dwResult=GetIpForwardTable(pRoutingTable,&dwBufferSize,FALSE);
if (dwResult==NO_ERROR) {
dwRowCount=pRoutingTable->dwNumEntries; // Get row count
// Look for default route to gateway
for (dwIndex=0;dwIndex<dwRowCount;dwIndex++) {
if (pRoutingTable->table[dwIndex].dwForwardDest==0) { // Default route designated by 0.0.0.0 in table
bIsInternetAvailable=TRUE; // Found it
break; // Short circuit loop
}
}
}
delete pRoutingTable; // Clean up. Just say "No" to memory leaks
return bIsInternetAvailable;
}
|
|
|
|
|
Bob...
Thanks Very much for your comprehensive reply.
The solution you suggest is the solution I have tried, it is from CodeGuru. It seems it will be my best solution, however I must get the Platform SDK installed correctly !!!!!!
Having downloaded the SDK from Microsoft, I have no idea if it is the 2005 (latest) version or weather I have the 2003 February virsion installed. How can I check what I have installed ?? Cant find the 2003 SDK on their site at all !!
If you dont have time to help further, then Thanks agsain for your time !!
Regards Phill !
|
|
|
|
|
Are you using VC++ 6.0, or are you using 7(2002),7.1(2003), 0r 8(2005)?
Only 6.0 requires the February 2003 SDK or earlier. I have 7.1 and it comes with it's own SDK right out of the package. I also have 6.0 on the same machine but I have the 2000 Platform SDK installed and the February 2003 SDK installed in their own directory paths and my VC++ 6.0 IDE paths for the includes, libs, and source point to these respectively.
The February 2003 SDK is no longer available for free download. Microsoft unfortunatley saw an opportunity to make some money and now charges roughly $10 (US) for a disc. I have not checked recently to see if it's available for purchase still.
Another source was the CD that came with the book "Programming Server-Side Applications for Microsoft® Windows® 2000 by Jason Clark and Jeffrey Richter". It had a Platform SDK dated in 2000 that has these files.
(slightly off topic)
If you are using VC+ 6.0 but cannot find a compatible SDK, you may want to invest in VC++ 7.1 (aka 2003) for those programs that use the SDK, GDI+, etc... I prefer VC++ 6.0 but I'm finding VC++ 7.1 compiled code outperforms my VC++ 6.0 code even without compiling with the optimizing compiler turned on. I only program native code and the VC++ 7.1 IDE actually requires more time to develop certain types of applications but the tradeoffs seem to balance especially since Microsoft seems deadset on making life miserable for those of us who try and continue to develop with 6.0.
Visual Studio 2005 (at least the beta 2) was unbearably slow when I tried it out but I noticed most software venders are selling out or discontinuing VC++ 7.1 (2003) so I would snag a copy before your choices get limited even further. (CompUSA.com still has a few copies) I would have chose not to upgrade if it wasn't for the same issues you are now facing.
Good Luck and I hope a solution that is compatible with your needs develops for you.
Bob
|
|
|
|
|
Thanks for your help bob.
Im using V6.... Looks like Ill have to humt around for a Feb 2003 SDK disk or update my Studio version!! In the mean time Ill gloss over this requirement. At least I understand my problem a little better now. Although Im amazed this 'internet connected' issue hasnt been better addressed, still there you go !
Thanks again
Regards Philip
|
|
|
|
|
Healdp wrote: The solution you suggest is the solution I have tried, it is from CodeGuru
I've been trying for a while to locate the comment to the article at codeguru that had this idea but have been unable to locate it. You don't happen to have the article title by any chance.
The technique works so well and many ask for ways to detect an ISP/network connection so I thought I'd post it in an article for the benefit of all but I wanted to make sure to credit the person who passed the idea on. If I remember correctly, he also referred to someone else in a give credit where credit is do kinda way.
Its a shame the technique didn't make it into the codeguru "...Goodies..." book. They instead included one of the other half baked schemes that don't work well as a frontline detection technique. Some additional detection schemes would provide additional connectivity info after this initial check but only those techniques have made it into easy to find articles.
If you know the name of person to give credit to, that would also help.
Anyway, thanks in advance
Bob
|
|
|
|
|
http://www.codeguru.com/cpp/i-n/internet/generalinternet/comments.php/c3437/?thread=43800
|
|
|
|
|
Edwin Eefting &
Patrick Philippot
Thanks.
|
|
|
|
|
Thanks Bob for tou patience in answering . But still i think you are not clear with my requirement.
I have an internet connection and i am able to determine the connection too. My question is: "Is there a way to know whether the existing internet connection is through a dial-up connection or Wifi-connection or an Ethernet connection?"
If i get this it will be a breakthrough in my project.
Sunil
|
|
|
|
|
InternetGetConnectedState() from Wininet.dll.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|