我必须将一个DWORD(无符号长)RGBA转换为四个int变量(R,G,B和A)到目前为止,我有这个函数将4个int转换为DWORD:
unsigned long RGBA2DWORD(int iR, int iG, int iB, int iA)
{
return ((iA << 24) | (iR << 16) | (iG << 8) | iB);
}
Run Code Online (Sandbox Code Playgroud)
我该如何将其转换回来?
就像是
struct RGBA
{
int R, G, B, A;
};
RGBA DWORD2RGBA(unsigned long dwColor)
{
static RGBA tmp;
//.......conversion process
return tmp;
}
Run Code Online (Sandbox Code Playgroud)
任何形式的帮助将不胜感激!:)
谢谢
我正在尝试在一个字符串变量中收集用户的输入,该变量在指定的时间内接受空格.
由于通常cin >> str不接受空格,所以我将使用<string>中的std :: getline
这是我的代码:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
for(int i = 0; i < n; i++)
{
string local;
getline(cin, local); // This simply does not work. Just skipped without a reason.
//............................
}
//............................
return 0;
}
Run Code Online (Sandbox Code Playgroud)
任何的想法?
我正在开发一个wxWidgets GUI应用程序,允许用户将文件上传到FTP服务器,并且访问FTP服务器需要一对用户名/密码.
据我所知,即使程序已经编译,STL字符串甚至char*字符串对最终用户是可见的,使用十六进制编辑器或字符串提取器,如Sysinternals字符串实用程序.
那么,有一种安全/可靠的方法来存储C++应用程序中的敏感信息吗?
PS.我不能在这个应用程序中使用.NET.
我正在寻找一种方法来检测具有相同进程名称的正在运行的进程的数量。
例如,我运行记事本三遍。
记事本.exe 记事本.exe 记事本.exe
所以它会返回3。
我目前有这些代码来检测正在运行的进程,但不计算其正在运行的进程数量。
#include <iostream>
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>
bool IsProcessRunning(const char *进程名称);
int main()
{
char *notepadRunning = (IsProcessRunning("notepad.exe")) ?“是”:“否”;
std::cout << "记事本正在运行吗?" << notepadRunning;
返回0;
}
bool IsProcessRunning(const char *进程名称)
{
PROCESSENTRY32 pe32 = { sizeof(PROCESSENTRY32) };
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPPROCESS, 0);
if(Process32First(hSnapshot, &pe32))
{
做
{
if(_tcsicmp(pe32.szExeFile, 进程名) == 0)
{
关闭句柄(hSnapshot);
返回真;
}
while(Process32Next(hSnapshot, &pe32));
}
关闭句柄(hSnapshot);
返回假;
}
任何形式的帮助将不胜感激:)
谢谢。
首先,我认为这个问题不是C#独立的.但也可以用于其他语言,如C.
我现在正在尝试解析以4字节little-endian格式存储整数的文件格式.TBH,我不知道little-endian格式和big-endian格式是如何工作的.
但我需要将它们转换为可用的int变量.
例如,02 00 00 00 = 2
到目前为止,我有这个代码转换前2个字节:(我使用FileStream.Read将原始数据存储到缓冲区变量)
int num = ((buffer[5] << 8) + buffer[4]);
Run Code Online (Sandbox Code Playgroud)
但它只会转换前两个字节.(示例中为02 00,而不是02 00 00 00)
任何形式的帮助将不胜感激:)
我需要根据数组的一个数组值对数组中的数组进行排序.
例如:
$data = array( array( 1, "Article One", 132, 12402773, 3 ),
array( 2, "Article Two", 251, 12519283, 5 ),
array( 3, "Article Three", 107, 12411321, 3 ),
array( 4, "Article Four", 501, 12228135, 4 ) );
Run Code Online (Sandbox Code Playgroud)
默认情况下,如果我打印每个数组的第二个元素:
我需要通过子数组的第3个元素按降序对其进行排序.
所以它会是这样的:
因为501> 251> 132> 107.
有什么建议吗?
我正在尝试创建自己的std :: string包装器来扩展其功能.但是在声明<<运算符时遇到了问题.到目前为止,这是我的代码:
我的自定义字符串类:
class MyCustomString : private std::string
{
public:
std::string data;
MyCustomString() { data.assign(""); }
MyCustomString(char *value) { data.assign(value); }
void Assign(char *value) { data.assign(value); }
// ...other useful functions
std::string & operator << (const MyCustomString &src) { return this->data; }
};
主程序:
int main()
{
MyCustomString mystring("Hello");
std::cout << mystring; // error C2243: 'type cast' : conversion from 'MyCustomString *' to 'const std::basic_string<_Elem,_Traits,_Ax> &' exists, but is inaccessible
return 0;
}
我希望cout将该类视为std :: string,因此我不需要执行以下操作:
std::cout << …
我有问题(基本上,我很困惑.)在尝试为我的wxWidgets GUI应用程序创建一个工作线程时,将修改其中一个GUI属性本身.(在这种情况下,wxTextCtrl :: AppendText).
到目前为止,我有2个源文件和2个头文件用于wx程序本身(不包括我自己的库,MySQL库等),比如MainDlg.cpp,它包含一个名为'MainDlg'的WxFrame派生类和MainForm.cpp,其中包含一个名为'MainForm'的wxApp派生类.
MainForm.cpp
#include "MainHeader.h" // contains multiple header files
IMPLEMENT_APP(MainForm)
bool MainForm::OnInit()
{
MainDlg *Server = new MainDlg(wxT("App Server 1.0"), wxDEFAULT_FRAME_STYLE - wxRESIZE_BORDER - wxMAXIMIZE_BOX);
Editor->Show();
return true;
}
Run Code Online (Sandbox Code Playgroud)
MainDlg.cpp:
#include "MainHeader.h"
BEGIN_EVENT_TABLE(MainDlg, wxFrame)
EVT_BUTTON(6, MainDlg::StartServer)
EVT_BUTTON(7, MainDlg::StopServer)
END_EVENT_TABLE()
CNETServerConnection *cnServCon;
std::string ServerIP, DBHost, DBUser, DBName, DBPass;
int UserCapacity, DBPort, ServerPort;
MYSQL *sqlhnd;
MainDlg::MainDlg(const wxString &title, long style) : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(301, 230), style)
{
cnServCon = new CNETServerConnection(100);
this->InitializeComponent();
}
void MainDlg::InitializeComponent()
{ …Run Code Online (Sandbox Code Playgroud) 我的问题很简单.在C++ STL中是否有PHP的preg_match()函数等效?
如果没有,你能告诉我另一种选择吗?
谢谢.