visual-c++-2005

Pthreads in Visual C++

只谈情不闲聊 提交于 2019-11-30 12:41:22
I'm experimenting with multithreading in Windows and was wondering whether I should use Win32 API use POSIX Threads for Windows Learning Pthreads would be useful if I tried to develop such applications on different platforms - but am I losing anything by not learning Win32 API? Or are both similar enough so that learning one allows me to figure out the other easily? Use Boost Threads. When C++0x comes along, we will have std::threads. Boost threads has the closest implementation to std threads. else use pthreads. Pthreads is second closest to std::threads, and formed the main basis of std

Find largest and second largest element in a range

风流意气都作罢 提交于 2019-11-27 22:27:55
问题 How do I find the above without removing the largest element and searching again? Is there a more efficient way to do this? It does not matter if the these elements are duplicates. 回答1: for (e: all elements) { if (e > largest) { second = largest; largest = e; } else if (e > second) { second = e; } } You could either initialize largest and second to an appropriate lower bound, or to the first two items in the list (check which one is bigger, and don't forget to check if the list has at least

Capturing cout in Visual Studio 2005 output window?

折月煮酒 提交于 2019-11-27 20:38:56
I created a C++ console app and just want to capture the cout/cerr statements in the Output Window within the Visual Studio 2005 IDE. I'm sure this is just a setting that I'm missing. Can anyone point me in the right direction? I've finally implemented this, so I want to share it with you: #include <vector> #include <iostream> #include <windows.h> #include <boost/iostreams/stream.hpp> #include <boost/iostreams/tee.hpp> using namespace std; namespace io = boost::iostreams; struct DebugSink { typedef char char_type; typedef io::sink_tag category; std::vector<char> _vec; std::streamsize write

Capturing cout in Visual Studio 2005 output window?

大憨熊 提交于 2019-11-26 20:25:09
问题 I created a C++ console app and just want to capture the cout/cerr statements in the Output Window within the Visual Studio 2005 IDE. I'm sure this is just a setting that I'm missing. Can anyone point me in the right direction? 回答1: I've finally implemented this, so I want to share it with you: #include <vector> #include <iostream> #include <windows.h> #include <boost/iostreams/stream.hpp> #include <boost/iostreams/tee.hpp> using namespace std; namespace io = boost::iostreams; struct

Why/when is __declspec( dllimport ) not needed?

泄露秘密 提交于 2019-11-26 18:49:25
In a project using a server.dll and a client.exe, I have dllexport ed a server symbol from the server dll, and not dllimport ed it into the client exe. Still, the application links, and starts, without any problem. Is dllimport not needed, then??? Details: I have this 'server' dll: // server.h #ifdef SERVER_EXPORTS #define SERVER_API __declspec(dllexport) #else #define SERVER_API // =====> not using dllimport! #endif class SERVER_API CServer { static long s; public: CServer(); }; // server.cpp CServer::CServer(){} long CServer::s; and this client executable: #include <server.h> int main() {