小编Tod*_*son的帖子

将向量的内容作为二进制数据写入文件

我有一些 15 年前的 C++ 代码,我正试图将它们带到更现代的时代。在这个阶段,我试图让用 Visual C++ 6.0 编译的代码现在用 VS 2003 (Microsoft Visual C++ .NET 69462-335-0000007-18915) 编译。

std::vector<myClassType> myVect;
...

// Assuming vector.begin() simply points to start of a contiguous array
bool OK = File.write((char*) myVect.begin(),
                     myVect.size() * sizeof(myClassType));
Run Code Online (Sandbox Code Playgroud)

当我阅读评论时,我很担心......我们真的可以假设向量在连续内存中吗?如果没有,有什么更好的方法可以做到这一点?我是否需要遍历向量内容并从 myClassType 写入每组数据?

事实上,编译器抱怨无论如何将 begin() 的结果转换为 char* 。

c++ vector

0
推荐指数
1
解决办法
1400
查看次数

为什么RemoveSplash不再是CMainFrame的成员?

此代码在Visual C++ 6.0下工作:

BOOL CSplashWnd::PreTranslateAppMessage(MSG *pMsg)
{
    if (c_pSplashWnd == NULL)
        return FALSE;

    // If we get a keyboard or mouse message, hide the splash screen.
    if ((pMsg->message == WM_KEYDOWN)       ||
        (pMsg->message == WM_SYSKEYDOWN)    ||
        (pMsg->message == WM_LBUTTONDOWN)   ||
        (pMsg->message == WM_RBUTTONDOWN)   ||
        (pMsg->message == WM_MBUTTONDOWN)   ||
        (pMsg->message == WM_NCLBUTTONDOWN) ||
        (pMsg->message == WM_NCRBUTTONDOWN) ||
        (pMsg->message == WM_NCMBUTTONDOWN))
    {
    // let main frame window remove the splash screen so timer is killed &
    // Tip-of-the-Day is displayed (if appropriate)
    CMainFrame …
Run Code Online (Sandbox Code Playgroud)

c++ mfc

0
推荐指数
2
解决办法
78
查看次数

标签 统计

c++ ×2

mfc ×1

vector ×1