小编Kel*_*ton的帖子

c ++标题保持理智

我在c ++中编写代码时遇到的最大问题是你必须在引用它之前声明一个类.说我有这样的两个头文件...

那么header1.h

#include "Header2.h"
#include <deque>
#include <string>
#include <iostream>
using namespace std;
class HelloPackage;
class Hello
{
public:
    string Message;
    HelloPackage * Package;
    Hello():Message("")
    {

    }
    Hello(string message, HelloPackage * pack)
    {
        Message = message;
        Package = pack;
    }
    void Execute()
    {
        cout << Message << endl;
        //HelloPackage->NothingReally doesn't exist.
        //this is the issue essentially
        Package->NothingReally(8);
    }
};
Run Code Online (Sandbox Code Playgroud)

Header2.h

#include "Header1.h"
#include <deque>
#include <string>
#include <iostream>
using namespace std;
class HelloPackage
{
public:
    deque<Hello> Hellos;
    HelloPackage()
    { …
Run Code Online (Sandbox Code Playgroud)

c++ header include

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

带有fread的随机字节

#post

我变量的名字并不重要!该代码将在工作时删除!

#post

好吧,所以我在stdio.h中使用fread来读取文本文件.问题是我一直在阅读文字文件中不存在的随机字节.我假设他们是文件方案的一部分,但我只是想确保它不是我的代码.

#include "stdafx.h"
#ifdef WIN32
    #include <io.h>
#else
    #include <sys/io.h>
#endif
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>

#include "n_script_timer.h"
//using namespace std;

#ifdef _INC_WCHAR
    typedef wchar_t CHR;
#else
    typedef char CHR;
#endif
int _tmain(int argc, CHR* argv[])
{
    #ifndef _DEBUG
        if(argc == 1)
        {
            printf("You must drag a file onto this program to run it.");
            scanf("%*c");
            return 0;
        }
        CHR* fname = argv[1];
    #else
        #ifdef _INC_WCHAR
            const CHR fname[16] = L"f:\\deleteme.bin";
        #else
            const CHR fname[16] …
Run Code Online (Sandbox Code Playgroud)

c++ winapi

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

malloc指针函数传递fread

无法弄清楚什么是错的,我似乎没有从恐惧中得到任何东西.

port.h

#pragma once
#ifndef _PORT_
    #define _PORT_
    #include <string>
    #ifndef UNICODE
        typedef char chr;
        typedef string str;
    #else
        typedef wchar_t chr;
        typedef std::wstring str;
        inline void fopen(FILE ** ptrFile, const wchar_t * _Filename,const wchar_t * _Mode)
        {
            _wfopen_s(ptrFile,_Filename,_Mode);
        }
    #endif
#endif
Run Code Online (Sandbox Code Playgroud)

在main()里面

    File * f = new File(fname,FileOpenMode::Read);
    chr *buffer;
    buffer = (wchar_t*)malloc(f->_length*2);
    for(int i=0;i<f->_length;i++)
    {
      buffer[i] = 0;
    }
    f->Read_Whole_File(buffer);
    f->Close();
    for(int i=0;i<f->_length;i++)
    {
      printf("%S",buffer[i]);
    }
    free(buffer);
Run Code Online (Sandbox Code Playgroud)

在文件类中

    void Read_Whole_File(chr *&buffer)
    {
        //buffer = (char*)malloc(_length);
        if(buffer == NULL) …
Run Code Online (Sandbox Code Playgroud)

c c++

-1
推荐指数
1
解决办法
1202
查看次数

NSIS选择一个文件

我想要做的是有一个页面,用户浏览文件系统中的特定值,如果文件名匹配则继续.具体来说,我希望用户找到php可执行文件,还有我想的目录(不知道我将如何从完整路径中提取目录).

nsis file

-1
推荐指数
1
解决办法
3514
查看次数

c#foreach with Action.BeginInvoke

好吧,所以我在这里遇到了一些问题.这是循环.

lock (ClientLocker)
{
    Trace.WriteLine("#WriteAll: " + sm.Header);
    foreach (Client c in Clients)
    {
        if (c.LoggedIn)
        {
            Trace.WriteLine("#TryWriteTo[" + c.Id + "](" + sm.Header + ")");
            LazyAsync.Invoke(() => c.WriteMessage(sm));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是LazyAsync

public static class LazyAsync
{
    public static void Invoke(Action a)
    {
        a.BeginInvoke(a.EndInvoke, null);
    }
}
Run Code Online (Sandbox Code Playgroud)

每个Client包含一个socket,所以我不能Clone这么做.问题是,当我执行Invoketo时c.WriteMessage,由于执行被延迟,它通常不会触发列表中的第一对,并且有时实际上只会在最后一项上触发一大堆.

我知道这与c是一个在Invoke实际被调用之前发生变化的引用有关,但有没有办法避免这种情况?

执行一般for(int i=0 etc循环似乎无法解决此问题.

任何人对我如何解决这个问题都有任何想法?

记住,不能Clone Client.

c# concurrency delegates action invoke

-1
推荐指数
1
解决办法
1204
查看次数

标签 统计

c++ ×3

action ×1

c ×1

c# ×1

concurrency ×1

delegates ×1

file ×1

header ×1

include ×1

invoke ×1

nsis ×1

winapi ×1