首页
社区
课程
招聘
[旧帖] [求助]这段代码哪里错了,不是编译错误,是逻辑错误。 0.00雪花
发表于: 2011-1-7 16:59 972

[旧帖] [求助]这段代码哪里错了,不是编译错误,是逻辑错误。 0.00雪花

2011-1-7 16:59
972
#include <iostream>
#include <string>
#include <Afxmt.h>
#include <vector>

using namespace std;
vector<string> temp;

CSemaphore semaphoreWrite(1,1);
CCriticalSection critical_section;

UINT Run(LPVOID lp)
{
        int i = 0;
        while(i<100)
        {
                critical_section.Lock();
                string tem;
                char sp[1024];
                sprintf(sp,"127.0.0.%d",i);
                tem = sp;
                temp.push_back(tem);
                i++;
                critical_section.Unlock();
                Sleep(3000);
               
        }
        return 1;
}

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
        AfxBeginThread(Run,NULL);
        vector<string>::iterator p = temp.begin();

        while(1)
        {
                critical_section.Lock();
                for(;p != temp.end();p++)
                {
                        cout<<p->c_str()<<endl;
                }
                p = temp.begin();
                critical_section.Unlock();
                Sleep(100);

        }
        return 0;
}

希望看雪的各位高手帮帮忙!谢谢了!

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (0)
游客
登录 | 注册 方可回帖
返回
//