gpt4 book ai didi

c++ - 为什么这个 C++ 程序不能编译?

转载 作者:行者123 更新时间:2023-11-30 00:40:33 26 4
gpt4 key购买 nike

这是我要编译的程序。

#include <iostream>
#include <string>
#include <vector>
#include <unistd.h>
using namespace std;

vector<string> paramlist;
const char *programname = "abc";

const char **args = new const char* [paramlist.size()+2]; // extra room for program name and sentinel
args [0] = programname; // by convention, args[0] is program name
for (int j = 0; j < paramlist.size()+1; ++j) // copy args
args [j+1] = paramlist[j] .c_str();

args [paramlist.size()+1] = NULL; // end of arguments sentinel is NULL

execv (programname, (char **)args);

当我尝试编译它时,我收到以下错误消息:

test.cpp:11: error: expected constructor, destructor, or type conversion before ‘=’ token
test.cpp:12: error: expected unqualified-id before ‘for’
test.cpp:12: error: expected constructor, destructor, or type conversion before ‘<’ token
test.cpp:12: error: expected unqualified-id before ‘++’ token
test.cpp:15: error: array bound is not an integer constant
test.cpp:15: error: expected constructor, destructor, or type conversion before ‘=’ token
test.cpp:17: error: expected constructor, destructor, or type conversion before ‘(’ token

最佳答案

你至少需要一个int main function .

关于c++ - 为什么这个 C++ 程序不能编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5798231/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com