无法从编程书中运行我的代码(C ++) [英] can't get my code to run from a programming book(c++)

查看:78
本文介绍了无法从编程书中运行我的代码(C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一本新的编程书(cameron hughes的多核编程,tracey hughes)。
到目前为止,我还没有他们的程序可以运行,这本书说它应该可以在99%的计算机上运行,​​所以我有点困惑,但是书中每个程序的末尾都有编译和链接说明 ...我需要输入吗?它看起来像这样的 C ++ -ogues_itguess_it.cc。现在运行的代码是:

i got a new programing book (multicore programming by cameron hughes, tracey hughes). so far i have not got one of their programs to work their book says that it should work on 99% of computers so im a little confused but at the end of each program in their book they have "compile and link instructions"... do i need to enter that? it looks something like this "C++ -o guess_it guess_it.cc". the code im runnning right now is:

#include <iostream>
#include <windows.h>
#include <string>
#include <spawn.h>
#include <sys/wait.h>

using namespace std;

int main(int argc,char *argv[],char *envp[])
{

 pid_t ChildProcess;
 pid_t ChildProcess2;
 int RetCode1;
 int RetCode2;
 int Value;
 RetCode1 = posix_spawn(&ChildProcess,"find_code",NULL,
                        NULL,argv,envp);
 RetCode2 = posix_spawn(&ChildProcess2,"find_code",NULL,
                        NULL,argv,envp);
 wait(&Value);
 wait(&Value);
 return(0);
 }

我运行Windows 7(32位),AMD athion x2 7550 Dual-核心处理器,VC ++ 2008 Express版。
i得到以下错误:致命错误C1083:无法打开包含文件:'spawn.h':没有这样的文件或目录

im running windows 7(32-bit), AMD athion x2 7550 dual-core proessor, VC++ 2008 Express edition. i get the following error : fatal error C1083: Cannot open include file: 'spawn.h': No such file or directory

任何人都知道我为什么可以'无法运行我的代码?我需要下载一些东西吗?因为我读过这本书,却没有看到有关下载任何内容的信息,但我可能是错的。 :(

anyone know why i can't get my code to run? do i need to download something? because i read the book and did not see anything about downloading anything but i might be wrong. :(

推荐答案

该书似乎正在使用POSIX线程。VisualStudio默认情况下使用Windows线程,这完全不同。 API。

It looks like that book is using POSIX threading. Visual Studio uses Windows Threading by default, which has a completely different API.

您很可能只需要获取适用于Windows的POSIX线程库。其中将包括 spawn.h 和相应的lib文件供您使用。

You most likely just need to get a copy of a POSIX Thread library for Windows. That will include spawn.h and the appropriate lib files for you to use.

这篇关于无法从编程书中运行我的代码(C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆