|
I I'm missing something or you are asking for (I cannot believe it...)
string::size_type s = 3;
s.find( "yht" , s ):
?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Sorry, what i meant is this
int main ()
{
string s("abcdefghijleeeeeeeyhtpr") ;
int now = 6 ;
int nowe = 3 ;
int result = nowe - now ;
string::size_type f = result ;
string::size_type loc2 = s.find( "yht" , f ) ;
cout << loc2 << endl ;
cout << f << endl ;
when i tried running this , i got the result displaying (4294967295 ). why is this? are we not allowed to use the variable (result) and put it to size_type f = result? is it not the same as size_type f = 3?
|
|
|
|
|
well, nowe-now is -3 , then cast it to unsigned ...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
gregarion wrote: when i tried running this , i got the result displaying (4294967295 ). why is this?
Perhaps because f (and result ) is -3 .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
gregarion wrote: What i would like to do is to be able to input a number and using that number as the index
What about:
int index;
cin >> index;
string::size_type loc2 = s.find("yht", index);
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Thanks guys, i got it. the issue was i thought that the output will start counting from the index i told it to. it only searches starting on the index, but output will be based from counting from the start of the file. Thanks!
|
|
|
|
|
Hallo,
I need to determine the current installed language of the os in Visual C++ 6.
Can someone help me? With which class I can get this value? Is it saved in the registry?
Thank you for helping me!
|
|
|
|
|
See the section here[^] on Locales and other regional options.
MVP 2010 - are they mad?
|
|
|
|
|
|
there is a problem existed in window7 and vista, if we set the autorange for the desktop application, that we can't send LVM_SETITEMPOSITION message, or it'll always return FALSE, why? it can take effect in windows xp.
|
|
|
|
|
The MSDN documentation[^] states:
On Windows Vista, sending this message to a list-view control with the LVS_AUTOARRANGE style does nothing, and the return value is FALSE.
I think you will need to talk to Microsoft for an explanation.
MVP 2010 - are they mad?
|
|
|
|
|
|
so, i can't exchange the position of the list items with the LVS_AUTOARRANGE style, my god.
|
|
|
|
|
That sounds quite reasonable if you have specified that they should be arranged automatically.
MVP 2010 - are they mad?
|
|
|
|
|
but it can exchange items' position if you dragging the icon on the desktop within the application of explorer.exe, i want to have the utility in my own application, how can i do? thanks in advance
|
|
|
|
|
Well I guess you need to suppress the auto arrange feature and implement it within your own code so that it looks the same. I have no idea how explorer does this, you might try asking Microsoft.
MVP 2010 - are they mad?
|
|
|
|
|
thanks for your advice
|
|
|
|
|
Hi,
I need to create a process like
LPTSTR szCmdline[] = TEXT("ffmpeg -i " + ofn.lpstrFile + " -r 1 -ss 00:00:10 -vframes 1 -f image2 " + Buffer + "\\Initframe10.bmp");
For this I will be using CreateProcess API but problem is how to convert TCHAR to a LPTSTR lpCommandLine to be passed to CreateProcess?
ofn.lpstrFile (LPTSTR type) is obtained as outcome of GetOpenFileName API Call and Buffer (TCHAR type) is obtained as GetTempPath.
I get compilation errors which I am not able to fix. (I am new to Win32 programming so this may sound naive).
Can someone please help me in fixing the errors?
Thanks
modified on Thursday, January 28, 2010 7:30 AM
|
|
|
|
|
|
Thanks, I have gone over first link and is really informative.
I will go over second link now.
|
|
|
|
|
I'm glad it helped you.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
WideCharToMultiByte() function can be used for conversion. You can also use a _bstr_t class which has an operator char* which can convert unicode to char*
|
|
|
|
|
As well as the other suggestions you should study the basics of arrays and pointers in C and how they are used.
MVP 2010 - are they mad?
|
|
|
|
|
Dear all,
I have a question about Winsock.
My program is a TCP client which manipulates lots of socket connection concurrently.
One socket for each thread.
I use blocking mode at most of time, except creating a new connection to server.
I turn socket into non-blocking mode first, then use select() to check the socket before turning back.
I really don't want to waste time on uncertain blocking timeout and make sure the connection is established in the specific time.
Everything works well when most of server are reachable.
But here comes the question.
If the number of unreachable server increases(more than 5), the rest reachable server will fail on creating connection.
In this case, select() always return 0(means timeout) even though the server is originally reachable.
Here is the portion of my program to create connection:
Open(LPCTSTR addr, int port, DWORD dwTimeout)
{
_socket = 0;
SOCKET theSocket;
int nRet;
LPHOSTENT lpHostEntry;
lpHostEntry = gethostbyname(addr);
if (lpHostEntry == NULL) {
return;
}
theSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (theSocket == INVALID_SOCKET) {
return;
}
unsigned long ul = 1;
nRet = ioctlsocket(theSocket, FIONBIO, (unsigned long*)&ul);
if (nRet == SOCKET_ERROR) {
closesocket(theSocket);
return;
}
SOCKADDR_IN saServer;
saServer.sin_family = AF_INET;
saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
saServer.sin_port = htons(port);
nRet = connect(theSocket,
(LPSOCKADDR)&saServer,
sizeof(struct sockaddr));
if (nRet == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK) {
closesocket(theSocket);
return;
}
struct timeval timeout;
fd_set r;
FD_ZERO(&r);
FD_SET(theSocket, &r);
timeout.tv_sec = dwTimeout / 1000;
timeout.tv_usec = (dwTimeout % 1000) * 1000;
nRet = select(0, 0, &r, 0, &timeout);
if (nRet <= 0 ) {
closesocket(theSocket);
return;
}
ul= 0;
nRet = ioctlsocket(theSocket, FIONBIO, (unsigned long*)&ul);
if (nRet == SOCKET_ERROR){
closesocket(theSocket);
return;
}
_socket = theSocket;
}
Is there anything wrong in this code?
Or any constraint on the number of unreachable socket select() concurrently in multithread?
|
|
|
|
|
luderjane wrote: I use blocking mode at most of time, except creating a new connection to server.
I turn socket into non-blocking mode first, then use select() to check the socket before turning back.
Just an idea, you could use a "master thread" to check for timeouts and close socket handles. This should make threads return from blocking connect() calls if necessary... and you can remove the select-timeout-code (untested).
/M
|
|
|
|