I have not used an iterator on a stringstream. Does std c++ have iterator? Thanks!
Yonggoo
I have not used an iterator on a stringstream. Does std c++ have iterator? Thanks!
Yonggoo
Hi All, I always appreciate your help. I have a problem with ifstream This is my 'input.txt' file. The first digit of each line is the length. How can I read in this file using while() or for() 2 3 4 5 7 8 10 11 12 7 8 10 16 17 54 37 38 3 33 51 48 ... I tried this one. ... ifstream inpf_EX("input.txt"); for (i=1; i<=N_Of_LINE;i++) { inpf_EX>>EXIST[i][0]); len=EXIST[i][0]; for(j=1; j<=len; j++) { inpf_EX>>EXIST[i][j]); } } Thanks! ...
Yonggoo
Hi all, I am not sure of the following code. vector::iterator it; for(it = vecGuiInSockets.begin(); it != vecGuiInSockets.end(); ++it) { (*it)->cleanup_socket(); delete (*it); it--; } vecGuiInSockets.clear(); First of all, what does the clear() clean? Does it just clean the pointers to Socket, or it cleans the object to which the pointer points? Second, is the for() loop correctly done? Thanks!
Yonggoo
Sorry mike!
Yonggoo
I have tried many ways. The following worked. double Clock::getLocalSeconds()const // The local time is hours behind. All else are the sams as UTC time. { time_t UtcTimeValue; time(&UtcTimeValue); //get the system time, which is UTC time struct tm* UtcHMS= gmtime(&UtcTimeValue); //convert it to struct tm*, which is UTC time int utcHours = UtcHMS->tm_hour; time_t LocalTimeValue; time(&LocalTimeValue); //get the system time, which is UTC time struct tm* LocalHMS = localtime(&LocalTimeValue); //convert it to struct tm*, which is the local time int localHours = LocalHMS->tm_hour; double diffHours =utcHours - localHours; return ((double)UtcTimeValue - diffHours*SECONDS_IN_HOUR); }
Yonggoo
We want to keep our system cross-platform. Any ANSI standard way to get local time in seconds?
Yonggoo
How to get local time in seconds? I am using MS Visual Studio 2005. I could get UTC time in seconds below. Are they correct? Thanks! #include #include double Clock::getUtcSeconds()const // returns UTC time in second { time_t UtcTimeValue; return time(&UtcTimeValue); } string Clock::getUtcHMSTime()const { char buffer[10]; string strUtcTime; time_t UtcTimeValue; time(&UtcTimeValue); struct tm* UtcTime = gmtime(&UtcTimeValue); //convert the calender time to UTC time strUtcTime+=itoa(UtcTime->tm_hour, buffer,10); //convert to decimal number strUtcTime+=" : "; strUtcTime+=itoa(UtcTime->tm_min, buffer,10); strUtcTime+=" : "; strUtcTime+=itoa(UtcTime->tm_sec, buffer,10); return strUtcTime; }
Yonggoo
Is this code OK! Node* Nodes[101]; refNodes& getNodes() { for(int i=1;i<=100; ++i) { Nodes[i] = new Node(); } return Nodes; } Thanks!
Yonggoo
I have three questions? ONE: It is said "using references is safer than using pointer." Why? TWO: If I want node objects in heap, how can I assign the pointers from heap memory? example code) Node& Nodes[100]; ? = new Node(); THREE: Is using pointers faster than using references? Thanks!
Yonggoo
N
Hi All, Is there any function in (standard) c++ that convert integer value to std:string object? Such as, ... int n = 123; string str_n = itos(n); ... or some efficient way? Thanks!
Yonggoo
Hi All, I am studying multithreading with Visual Studio 2005. I have an error with one sample from "Multithreading Applications in Win32 - Jim Beveridge & Robert" 1>.\SearchFile.cpp(44) : error C2664: '_beginthreadex' : cannot convert parameter 3 from 'DWORD (__stdcall *)(void *)' to 'unsigned int (__stdcall *)(void *)' /* SerarhFil.cpp */ #include #include #include #include #include #include "MtVerify.h" DWORD WINAPI SearchProc(void *arg); #define MAX_THREADS 3 HANDLE hThreadLimitSemaphore; char szSearchFor[1024]; int main(int argc, char *argv[]) { WIN32_FIND_DATA* lpFindData; HANDLE hFindFile; HANDLE hThread; DWORD dummy; int i; if(argc != 2) { printf("Usage: %s \n", argv[0]); return EXIT_FAILURE; } strcpy(szSearchFor, argv[1]); lpFindData = (WIN32_FIND_DATA*) calloc(1, sizeof(WIN32_FIND_DATA)); MTVERFY(hThreadLimitSemaphore = CreateSemaphore(NULL, MAX_THREADS, MAX_THREADS, NULL)); hFindFile = FindFirstFile("*.c", lpFindData); if(hFindFile == INVALID_HANDLE_VALUE); return EXIT_FAILURE; do{ WaitForSingleObject(hThreadLimitSemaphore, INFINITE); //HERE MTVERFY(hThread = (HANDLE) _beginthreadex(NULL, 0, SearchProc, lpFindData, 0, &dummy)); MTVERFY(CloseHandle(hThread)); lpFindData =(WIN32_FIND_DATA*)calloc(1, sizeof(WIN32_FIND_DATA)); }while(FindNextFile(hFindFile, lpFindData)); FindClose(hFindFile); for(i=0; icFileName, "r"); if(!ptrFile) return EXIT_FAILURE; while(fgets(buff, sizeof(buff), ptrFile)) { if(strstr(buff,szSearchFor)) printf("%s: %s", lpFindData->cFileName, buff); } fclose(ptrFile); free(lpFindData); MTVERFY(ReleaseSemaphore(hThreadLimitSemaphore, 1, NULL)); }
Yonggoo
Hi all, I am having runtime crash with code below int main(int argc, char** argv) { vector iVec; iVec.push_back(0); iVec.push_back(10); iVec.push_back(20); iVec.push_back(30); iVec.push_back(40); iVec.push_back(30); iVec.push_back(60); vector::iterator it; for(it=iVec.begin(); it != iVec.end();++it) { if(*it = 30) { iVec.erase(it); } --it; } return 0; } How can I get all "30" out? Thanks!
Yonggoo
I found it! In Visual Studio 2005 Standard IDE, there is option about multithreaded. In general condition, Properties/configuration properties/C/C++/code generation/runtime library But, in some conditions that option is not available,like when we chose 'empty project'. As long as I know! Thanks! Yonggoo -- modified at 16:57 Wednesday 31st May, 2006
I am using Visual Studio 2005 Standard, C++. How to set IDE for Multithreading? Some say Properties /Code Generation, but I don't see on my IDE. Could anyone help me? Thanks! Yonggoo
Hi, I am having errors. error C2664: 'Menu::createMenuItem' : cannot convert parameter 3 from 'std::_Vb_reference<_MycontTy> *__w64 ' to 'bool *' ... vector connect_flags; vector disconnect_flags; ... for(int j=0;jpMenu->createMenuItem(mhComm, (connect_str+gMenuState.getGosafeStation(j).name).c_str(), &(gMenuState.connect_flags[j]), &_menuHeaderCommFn); this->pMenu->createMenuItem(mhComm, (disconnect_str+gMenuState.getGosafeStation(j).name).c_str(), &(gMenuState.disconnect_flags[j]), &_menuHeaderCommFn); } Anybody can help me? Yonggoo -- modified at 18:50 Thursday 13th April, 2006
Hi, I am having errors. error C2664: 'Menu::createMenuItem' : cannot convert parameter 3 from 'std::_Vb_reference<_MycontTy> *__w64 ' to 'bool *' ... vector connect_flags; vector disconnect_flags; ... for(int j=0;jpMenu->createMenuItem(mhComm, (connect_str+gMenuState.getGosafeStation(j).name).c_str(), &(gMenuState.connect_flags[j]), &_menuHeaderCommFn); this->pMenu->createMenuItem(mhComm, (disconnect_str+gMenuState.getGosafeStation(j).name).c_str(), &(gMenuState.disconnect_flags[j]), &_menuHeaderCommFn); } Anybody can help me? Yonggoo -- modified at 18:51 Thursday 13th April, 2006
Hi, I am making a program to print out both UTC time and local time. But, I am having the same time. Do I have to save UTC time before 'ptrLocalTime = localtime(&localtimer);'? /* This program shows UTC time, and local time in 00:00:00 */ #include #include #define PST (-8) //Pacific Time Zone #define CST (-6) //Central Time Zone int main () { time_t timer; time_t localtimer; tm* ptrUTC; tm* ptrLocalTime; time ( &timer ); //Set timer to the number of seconds elapsed since 00:00 hours, //Jan 1, 1970 UTC from the system clock. time(&localtimer); ptrUTC = gmtime ( &timer ); //Converts timer to tm structure adjusting to UTC //(formerly known as GMT) timezone. ptrLocalTime = localtime(&localtimer); printf ("UTC Time: %2d:%02d:%02d\n", ptrUTC->tm_hour, ptrUTC->tm_min, ptrUTC->tm_sec); printf ("Locat time : %2d:%02d:%02d\n", ptrLocalTime->tm_hour, ptrLocalTime->tm_min, ptrLocalTime->tm_sec); return 0; } Please! Yonggoo
Hi, I am having this run time error message. Run-Time Check Failure #2 - Stack around the variable 'buffer' was corrupted. It makes sense for me, but Anybody could give me some detail ideas about this error message? Thanks! Yonggoo
Hi! I am trying to run an .exe file in my C++ code. Let me say, I have do.exe program. And another control_do.exe program that can run do.exe conditionally. Any code suggestion that is generic, not VC++? I am using Visual Studio 2005, but code is standard c++, but VC++. Thanks! Yonggoo
Hi! In a window, there are several triangle objects. I want one of these to blink if I hit a button that is related with. I don't want to use any MFC etc, only standard c++ and OpenGL. Is there any good way? Yonggoo