|
That was exactly what I was looking for!
Thank you very much!
|
|
|
|
|
Could you tell me what books like Real World .NET Application ?
The book has some good application for learning.
Thanks in advance
|
|
|
|
|
How to use CByteArray to store large data into Oracle database.
|
|
|
|
|
dear friends,
I'd a problem. I want to instatite a template class like this
MaxHeap<Array<int>> m; I'm using vc++. Why it is so. The code is working if i'm changing code and using like MaxHeap<Array> m;Why it is so. How to solve this problem. Please help me in this aspect.
But compiler is giving errors like
Compiling...
heap.cpp
d:\cpppractice\sep3\heap.cpp(13) : error C2146: syntax error : missing ',' before identifier 'm'
d:\cpppractice\sep3\heap.cpp(13) : error C2065: 'm' : undeclared identifier
d:\cpppractice\sep3\heap.cpp(13) : error C2143: syntax error : missing '>' before ';'
Error executing cl.exe.
heap.obj - 3 error(s), 1 warning(s)
complete code is:
# include <iostream>
# include <Heap1.h>
using namespace std;
using namespace bhadram1;
int main()
{
int array[10]={20,12,35,15,10,80,30,17,2,1};
Array<int> a(array,10);
Array<int> a1(a);
MaxHeap<Array<int>> m;
//m.initilize(a,10,10);
//m.print();
return 0;
}
# include <iostream>
using namespace std;
namespace bhadram1
{
template<class T>
class Array
{
//friend ostream& operator<<(ostream& ostr,String& s);
protected:
int size;
T* data;
public:
Array()
{
size=1;
data=new T[1];
}
Array(int n)
{
size=n;
data=new T[size];
}
Array(int* a,int const s)
{
size=s;
data=new T[size];
for(int i=0;i<s;i++)
{
data[i]=*a++;
cout<<data[i]<<endl;
}
}
Array(Array<T>& a)
{
size=a.size;
//delete[] data;
data=new T[size];
for(int i=0;i<size;i++)
{
data[i]=a.data[i];
}
}
T& operator[](int i)
{
return data[i-1];
}
};
template<class T>
class MaxHeap
{
private:
int currentSize,maxSize;
public:
MaxHeap()
{
currentSize=0;
}
void initilize(T a,int size,int arraySize)
{
T heap(size);
for(int j=1;j<=10;j++)
{
heap[j]=a[j];
cout<<heap[j];
}
currentSize=size;
maxSize=arraySize;
for(int i=currentSize/2;i>=1;i--)
{
int y=heap[i];
cout<<"a "<<a[i]<<" y "<<y;
int c=2*(i);
cout<<"c "<<c<<" current "<<currentSize<<endl;
while(c<=currentSize)
{
cout<<"sub c "<<c<<endl;
if(c<currentSize && heap[c]<heap[c+1])
c++;
if(y>=heap[c])
break;
heap[c/2]=heap[c];
c*=2;
}
heap[c/2]=y;
}
for(i=1;i<=10;i++)
{
cout<<"final "<<heap[i]<<endl;
}
}
void print()
{
}
};
};
Thanking you,
yours sincerely,
bhadram
bhadram
|
|
|
|
|
>>MaxHeap<array<int>> m; I'm using vc++. Why it is so
Because you need to pust a space between >>
Example:
MaxHeap<array<int> > m;
It'll work if you put the space in. The space is required, because the compiler see this >> as operator >> (instead of template brackets).
Top ten member of C++ Expert Exchange.
http://www.experts-exchange.com/Cplusplus
|
|
|
|
|
Hi,
I have a MDI project.
How can I exchange data from one Editcontrol to another editcontol. I open two instances of a view.
I change the text of the Editcontrol in one view.
Afterwards, I close the view. The changed text should appear to the second view in the Editcontrol.
Can you help me please?
Klef
|
|
|
|
|
Hi,
You may use the CDocument::UpdateAllView method.
This will call the OnUpdate method of all view instances which are currently displaying the same CDocument object.
Eric
"If it is not broken, do not fix it"
|
|
|
|
|
Hi,
Thank you for your answer.
Is there in the forum possibly an example which I could look at myself the thing times?
Best regards
|
|
|
|
|
I want to use VC++ *.lib into C# application. I know that I must compile the lib in to a dll. How can i do that? Any method and hits to me.
|
|
|
|
|
IMO, the easiest way is to create a DLL that exports functions that simply call the .LIB functions:
BOOL __stdcall fooFunc_DLL(int p)
{
return fooFunc_LIB(p);
}
that way, you don't have to change the .LIB functions, and the DLL is a simple one-step pass through.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
I suggest you start reading here[^] in the MSDN about DLL's. In order to use your object library (the .lib file) as a DLL, you may need to create a DllMain function in a .C or .CPP source file, compile it, and link it to your .lib.
You will need to research further what it takes to use a DLL from C#; that's something I don't know about.
By the way: I don't know who the two boneheads were that rated your post a 1. I think your question is valid, asked politely, and in the correct forum. Good luck.
Software Zen: delete this;
|
|
|
|
|
Hi
I am using SQL Server for my database programming using CRecordset. but now i have to use Oracle. I am connecting to Oracle using ODBC. How to access tables from Oracle. Tables having BLOB datatype fields. how to access Oracle through VC++. Can u plz guide me.
Thanks in advance.
|
|
|
|
|
Hello,
You can use CDatabase and CRecordset classes for accessing the database and retrieving the records from Oracle. While passing any query when you mention the table name is sufficient, as the ODBC will be connecting to the whole of the database and tables are part of the database.
If the reply helps you, Don't forget to rate it.
|
|
|
|
|
the code below is weirld casue when the change is mutiple by 100(0.67 * 100)
it change to 66 please heplp me solve this
#include iostream
using namespace std
int bugger;
float change=0.67;
int moeny[6][2];
int cointo[6];
float cash;
bugger = (float)change * (float)100;
cout<< "change2: "<<bugger<<endl;
while(bugger !="0" &&="" cash="" if(bugger="">= 100 && money[0][1] !=0)
{
money[0][1]--;
bugger=bugger-100;
cointo[0]++;
cout<< "bugger: "<<bugger<<endl;
}
="" else="" if(bugger="">= 50 && money[1][1] !=0)
{
money[1][1]--;
bugger=bugger-50;
cointo[1]++;
cout<< "change: "<<bugger<<endl;
}
="" else="" if(bugger="">= 20 && money[2][1] !=0)
{
money[2][1]--;
bugger=bugger-20;
cointo[2]++;
cout<< "change: "<<bugger<<endl;
}
="" else="" if(bugger="">= 10 && money[3][1] !=0)
{
money[3][1]--;
bugger=bugger-10;
cointo[3]++;
cout<< "change: "<<bugger<<endl;
}
="" else="" if(bugger="">= 5 && money[4][1] !=0)
{
money[4][1]--;
bugger=bugger-5;
cointo[4]++;
cout<< "change: "<<bugger<<endl;
}
="" else="" if(bugger="">= 1 && money[5][1] !=0)
{
money[5][1]--;
bugger=bugger-1;
cointo[5]++;
cout<< "change: "<
|
|
|
|
|
'int moeny[6][2]' (money after) is not initialized ...
'int cointo[6]' is not initialized ...
'float cash' is not initialized ...
before using.
|
|
|
|
|
this is only a part of the code the problem wit this code is that when then chagne is store in the bugger it always change example((bugger)6.7 = (change)6.6) it always change to a diferant number so can please tell me why please
|
|
|
|
|
You get this problem because of the way floating point numbers are represented, and the way types are converted.
When you convert a float to an integer, for example in the statement:
bugger = (float)change * (float)100;
the float is truncated (i.e. the fractional part is discarded.)
When you multiply two floats (eg 0.67 by 100.0), the answer will not be exactly an integer (eg. 67) - it will be slightly more or slightly less. Since the result you get after truncating is 66, this implies the float representation is less than 67, i.e. 66.9999 . . . Truncating 66.99999 gives 66.
The solution - add some small number to the result before truncating, as below
bugger = (float)change * (float)100 + 0.0001;
|
|
|
|
|
|
I had been taught not to use goto or switch. However a lot of professional code uses both.
Is the switch statement any faster than a lot of if anf else if's? In other words, is switch the same thing as a lot of if else ifs from a machine code point of view?
|
|
|
|
|
I agree it's a good idea to avoid goto, but in my opinion there are correct applications for switches and I would not be surprised to see them in professional code.
I doubt there is much difference between if's and switches in terms of speed. I think the main issue is clarity. The switch is just easier to read if there are a lot of states to be tested.
Best Regards
Cliff
-- modified at 5:11 Sunday 4th September, 2005
|
|
|
|
|
With today's compilers, switches and ifs can perform about the same. You will often find that a compiler will convert a switch statement to a series of ifs and maybe even visa-versa.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
While there may be a valid use for goto , I've not used it in years. You can always organize your code so that it isn't necessary, and the modified code is almost invariably more robust.
I am curious. Why were you taught to not use switch ? While it can be misused, overall it has its applications. Any time you have a discrete value (an enum , for example) that specifies an action, a switch statement is appropriate.
The object-oriented programming crowd would argue that you should create a class structure, and derive unique classes for each case. That approach is inefficient and overkill a lot of the time. It also makes it a lot more difficult to follow program logic.
Software Zen: delete this;
|
|
|
|
|
I agree. Thanks for your response.
|
|
|
|
|
////////////////////////////func A: App's member function ////////////////////////////////////////////////////
newIndex = pRWapp->GetEmptySocket();
if ( newIndex != -1 )
{
myOver = &(pRWapp->m_clientStructArray[newIndex]);
SOCKADDR_IN clntAddr;
int addrLen = sizeof(clntAddr);
myOver->socket = accept( pRWapp->m_serverSocket, (SOCKADDR*)&clntAddr, &addrLen );
if(pRWapp->m_bKillThreads==TRUE)
{
return 0L;
}
if(myOver->socket == INVALID_SOCKET)
{
// this area left out...for shortness
}
memcpy(&(myOver->clntAddr),&clntAddr,addrLen);
if ( myOver->socket != INVALID_SOCKET )
{
user = newIndex * 2;
ZeroMemory( &(myOver->recvOverlapped.Overlapped), sizeof(OVERLAPPED) );
ZeroMemory( &(myOver->sendOverlapped.Overlapped), sizeof(OVERLAPPED) );
CreateIoCompletionPort( (HANDLE)(myOver->socket),
pRWapp->m_gCompletionPort, DWORD(myOver), 0 );
myOver->recvOverlapped.wsabuf.buf = myOver->recvOverlapped.buffer;
myOver->recvOverlapped.wsabuf.len = BUFSIZE - 1;
==> this Func A 's function is to save data to m_clientStructArray[]....
////////////////////////////func B : App's member function ////////////////////////////////////////////////////
CPortClientScks* pPortCliSkc = new CPortClientScks;
pPortCliSkc->sockHandle = m_clientStructArray[index];
m_XXX_Port_SockList.AddTail(pPortCliSkc);
==> func B 's function is to save m_clientStructArray 's content to m_XXX_Port_SockList....
////////////////////////////func C: App's function////////////////////////////////////////////////////
POSITION sndXXXPos ;
sndXXXPos = m_XXX_Port_SockList.GetHeadPosition();
CPortClientScks* pSndXXXSck = NULL;
while(sndXXXPos != NULL )
{
pSndXXXSck = (CPortClientScks*)m_XXX_Port_SockList.GetNext(sndXXXPos);
if(m_pSndXXXSck->sockHandle.ID != "")
{
DWORD sendbytes;
strncpy(pSndXXXSck->sockHandle.sendOverlapped.wsabuf.buf,(LPCTSTR) pByte, bytes);
pSndXXXSck->sockHandle.sendOverlapped.wsabuf.len = bytes;
WSASend( pSndXXXSck->sockHandle.socket, &(pSndXXXSck->sockHandle.sendOverlapped.wsabuf),1,
&sendbytes, 0, &(pSndXXXSck->sockHandle.sendOverlapped.Overlapped), NULL );
}
}
//////////////////////////// following three lines are added to last of func C to check out the content of m_XXX_Port_SockList /////////////////////
sndXXXPos = m_XXX_Port_SockList.GetHeadPosition();
if(sndXXXPos != NULL)
pSndXXXSck = (CPortClientScks*)m_XXX_Port_SockList.GetNext(sndXXXPos);
==> func C' function is to look over m_XXX_Port_SockList's content...
and the structure of SOCKHANDLE IS....
typedef struct _MYSOCKHANDLE
{
SOCKET socket;
char ID[MAX_ID_LEN];
SOCKADDR_IN clntAddr;
MYOVERLAPPED recvOverlapped;
MYOVERLAPPED sendOverlapped;
}SOCKHANDLE, *LPSOCKHANDLE;
this SOCKHANDLE structure is used at m_clientstructArray[], and m_xxx_port_sockList's node member
the problem of this my code is that Getnext returns different value at second GetNext at added 3 lines especially after comed out of func C 's while loop....
but pPortCliSkc's value returned from func B 's new has proper value....
but, func C 's added GetNext return another value.....
why this happens?
GetHeadPosition 's return value is always same but
GetNext value is different , inside of Fucn C's while loop first entered,
but come out of while loop and added Getnext's return value is different ?
why?
please help me....
-- modified at 21:36 Saturday 3rd September, 2005
|
|
|
|
|
I get a fatal error from an article posted on here.
http://www.codeproject.com/w2k/makexp.asp
Here's the exact error:
http://students.etsu.edu/zbkc9/error.png[^]
I've also tried include fstream without the .h and get different errors. Any ideas? Thanks. I'm wanting to learn C++ and I have Visual Studio .NET 2003 Professional. NOt sure if the version matters, but thought I would post it in case.
|
|
|
|