|
for (i = 0; i < nx; i++)
{
for (j = 0; j < ny; j++)
{
if (cellV[i][j] > 0)
{
cellsV[i][j] = cellV[i][j] * cellV[i][j];
if (cellsV[i][j] > noise_border)
{
ofstream BuiltMap;
BuiltMap.open("C:\\My Files\\BuiltMap\\BuiltMap.txt", ios::in);
while (! BuiltMap.eof())
{
BuiltMap << "\n" << " " << cellsV[i][j];
}
}
else
cellsV[i][j] = NULL;
}
}
} Aside from the fact that the opening/closing of the file should be done outside of the loops, I'm not quite sure what you are doing here. You've got an ofstream object that is opening a file for input (i.e., reading), yet you are usign the << operator to write to it. Is this intentional?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I thought ifstream is made for reading files only, and ofstream to be able to write into file. Did I miss something there?
I want to write the values cellsV[i][j] into the BuiltMap file.
THX
|
|
|
|
|
So shouldn't you be opening the file with ios::out instead?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I am seeing an interesting problem using the SortChildrenCB
functionality in the CTreeCtrl class. When I add items to my
treectrl, I set the item data correctly with SetItem, along with some
other things, like the state, statemask. For my "private" item data I
am storing the HTREEITEM that I got back from the
CTreeCtrl::InsertItem call. I correctly cast it to an LPARAM from an
HTREEITEM.
The item gets added correctly and the SetItem also seems to work ok.
So, if I added two nodes to the tree the following values are used:
name1: "apples"
itemdata1: 713A8 (the HTREEITEM of the first node)
name2: "model"
itemdata2: 74008 (the HTREEITEM of the second node)
After adding each node, I fill the appropriate TVSORTCB structure as
follows:
tvs.hParent = parentH; // HTREEITEM of parent node
tvs.lpfnCompare = CompareItems; // address of my compare callback
routine
tvs.lParam = (LPARAM) &ctlTree; // pointer to my treectrl
ctlTree.SortChildrenCB(&tvs);
Now, when my callback routine gets called after adding the second item
to determine which way to sort the items, it gets called with the
itemdata of the first item, itemdata of the second item, and the "sort
parameter. I cast these accordingly:
CTreeCtrl* pMyTreeCtrl = (CTreeCtrl*) lParamSort;
// the lParam of an item is just it's handle
HTREEITEM hTreeItem1 = (HTREEITEM) lParam1;
HTREEITEM hTreeItem2 = (HTREEITEM) lParam2;
The problem is as follows:
the HTREEITEM of the first item gets munged -- by 2. So what I see
in the callback routine for HTREEITEMS is as follows:
hTreeItem1: 713AA (the HTREEITEM of the first node)
hTreeItem2: 74008 (the HTREEITEM of the second node)
Notice the difference in the value of the first handle. It should be
713A8, which is the correct node handle. This fouling up my sorting.
My question is this, to node handles persist? Do they live as long as
the tree node exists? Or, do they get reassigned during
expansion/contraction? In the past, I have hung pointers of more
complex "item data" on tree nodes without trouble. Of course I had to
be responsible for deallocating them when appropriate. But in this
case I thought I was safe using the HTREEITEM as item data, since
given that I could query the tree node for the sorting information I
needed.
Anyone have any ideas on this or have seen this behavior before?
Thanks in advance.
Roy Berger
roybrew@att.net
Regards,
Roy
_____________
Roy H. Berger
roybrew@att.net
|
|
|
|
|
An error occured when I use a function called "PESDEMUX_ProcessFile" which is defined in a Dll (XtlPes.dll) (I have no errors at compilation).
The error message I have is "Unhandled exception in Appli.exe (XTLPES.DLL): 0xC0000005:Access Violation."
The code I used is:
HINSTANCE g_hDllXtlPes; // Global Variable defined in the general class
g_hDllXtlPes = LoadLibrary("XtlPes.dll"); //
typedef LONG (__cdecl *PESDEMUX_ProcessFile)(CHAR*,CHAR*,INT);
PESDEMUX_ProcessFile pPESDEMUX_ProcessFile;
CHAR chInFileName[255];
strcpy(chInFileName, m_csPCFileName); //Conversion CString to CHAR*
CHAR chOutFileName[255];
m_csPCFileName = m_csPCFileName + ".mpg";
strcpy(chOutFileName, m_csPCFileName); //Conversion CString to CHAR*
INT Type = 1;
if (theApp.g_hDllXtlPes != NULL)
{
pPESDEMUX_ProcessFile = (PESDEMUX_ProcessFile)GetProcAddress(theApp.g_hDllXtlPes,"PESDEMUX_ProcessFile");
if (!pPESDEMUX_ProcessFile)
{
FreeLibrary(theApp.g_hDllXtlUsb);
return FALSE;
}
else
{
BOOL BResult = TRUE;
BResult = pPESDEMUX_ProcessFile(chInFileName,chOutFileName,Type);
}
}
Does someone have an idea ?
Thank's for advance.
|
|
|
|
|
use a debugger to determine what is going wrong!
Don't try it, just do it!
|
|
|
|
|
That's what I've done... But the function I use always returns FALSE...
Any ideas?
|
|
|
|
|
If LoadLibrary() fails, you shouldn't bother doing that other stuff.
HINSTANCE g_hDllXtlPes;
g_hDllXtlPes = LoadLibrary("XtlPes.dll");
if (NULL != g_hDllXtlPes)
{
typedef LONG (__cdecl *PESDEMUX_ProcessFile)(CHAR*,CHAR*,INT);
PESDEMUX_ProcessFile pPESDEMUX_ProcessFile;
CHAR chInFileName[255];
strcpy(chInFileName, m_csPCFileName);
CHAR chOutFileName[255];
m_csPCFileName = m_csPCFileName + ".mpg";
strcpy(chOutFileName, m_csPCFileName);
INT Type = 1;
pPESDEMUX_ProcessFile = (PESDEMUX_ProcessFile)GetProcAddress(theApp.g_hDllXtlPes,"PESDEMUX_ProcessFile");
if (NULL != pPESDEMUX_ProcessFile)
{
BOOL BResult;
BResult = pPESDEMUX_ProcessFile(chInFileName,chOutFileName,Type);
}
else
{
DWORD dwResult = GetLastError();
FreeLibrary(theApp.g_hDllXtlUsb);
return FALSE;
}
}
else
DWORD dwResult = GetLastError(); Note the calls to GetLastError() .
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
GetLastError() return 0.
Any ideas ?
|
|
|
|
|
So g_hDllXtlPes is NULL and GetLastError() returned 0. Is that right?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
g_hDllXtlPes is not NULL but GetLastError() returned 0
|
|
|
|
|
Ok, so what's the problem? If g_hDllXtlPes is not NULL , I would expect GetLastError() to return 0. That means no error!
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
True but I have an error message "Unhandled exception in Appli.exe (XTLPES.DLL): 0xC0000005:Access Violation"...
And I haven't the result I would like to have which is the conversion of a file...
|
|
|
|
|
Set a breakpoint on the LoadLibrary() statement and step through each successive statement until the exception occurs. My guess is that you are calling the PESDEMUX_ProcessFile() function incorrectly or with invalid parameters.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Hi !
I'm using the std::vector class. Let's say my vector has 10 elements. I want to reach, with an iterator the fifth.
Here is what I'd like to do :
std::vector::iterator MyIt=MyVector.begin();
MyIt=MyIt+5;
MyResult=(*MyIt);
But it doesn't work. The only way I could make it work is to have a loop which will do five time ++MyIt !
Why can't I just to MyIt=MyIt+5 ? Any suggestions ?
Thanks !
Jerome
|
|
|
|
|
std::vector has random access iterators so you should be able to to do MYIt = MyIt + 5;
If you dont want to use a loop, you can use advance, which works for both random access and forward/reverse iterators.
#include < vector >
#include < iostream >
#include < algorithm >
using namespace std;
int main(int argc, char* argv[])
{
vector< int > v;
for (int i = 0;i<10;++i)
v.push_back(i);
vector< int >::iterator it = v.begin();
it = it + 5;
cout << *it << endl;
advance(it, 2);
cout << *it << endl;
return 0;
}
---
“Our solar system is Jupiter and a bunch of junk” - Charley Lineweaver 2002
|
|
|
|
|
It works here ...
vector<int> MyVector;
for(int i = 0; i < 10; i++)
MyVector.push_back(i +1);
std::vector<int>::iterator MyIt = MyVector.begin();
MyIt=MyIt+5;
int MyResult = (*MyIt);
cout << MyResult << endl;
MyIt = MyIt + 3;
MyResult = (*MyIt);
cout << MyResult << endl;
Result screen:
6
9
<b>Maxwell Chen</b>
|
|
|
|
|
Looks like it might just be a syntax error. Try changing
std::vector::iterator MyIt=MyVector.begin(); to
std::vector‹int›::iterator MyIt=MyVector.begin();
Notice the ‹int› after vector. Wow I never realized how much of a pain it was to put angle brackets in.
- Aaron
|
|
|
|
|
Hi all;
I am having some serious problems with CDialogBar. I cannot initialise the controls found on it. Its the tenth time that i am posting (posted as Krugger) this particular topic but i have not yet gone through it. Can somebody please help me. If you want a copy of the class implementation as well as a screenshot of the application i am developing to better understand, please mail me and i will send it to you.
Thank you for your help
|
|
|
|
|
Hi all;
I am having some serious problems with CDialogBar. I cannot initialise the controls found on it. Its the tenth time that i am asking for help for this particular topic but i have not yet gone through it. Can somebody please help me. If you want a copy of the class implementation as well as a screenshot of the application i am developing to better understand, please mail me and i will send it to you.
Thank you for your help
|
|
|
|
|
how can i show the contents of "cout" used in C++ in Visual C++ 6 ?
|
|
|
|
|
If you meant that you wants to show some texts with cout with VC++6, here's the simple example.
#include <iostream>
using namespace std;
void main()
{
int iAge = 29;
cout << "Hello.\n" << "My age = " << iAge << endl;
}
Maxwell Chen
|
|
|
|
|
Or you can try :
cout.flush()
~RaGE();
|
|
|
|
|
HELLO!
PLEASE HELP ME!
I'm new in C/C++ programming.
And i have a problem:
here is the code:
char ch=fgetc(filein);
char s[20]="";
Now what I want is to put in string s the value that is the ord(c).
Example:if c is 'a' then I want put in s value "97".
This part of my code is written in ANSI/C language.
How can I do this?
Thank you very much!
|
|
|
|
|
I assume that ord(c) should return you the ASCII value of char c (maybe I misunderstand you). Therefore,
char c = 'a';
is equivalent to
char c = 97;
Then to get a string like "97", I would recommend using sprintf, as explained in Mike's FAQ on this link.
sprintf ( s, "%d", c );
Hope this helps.
~RaGE();
|
|
|
|