C++ 从main调用函数时出错

C++ 从main调用函数时出错,c++,C++,我试图从一个主函数调用两个函数。我的主函数代码如下: #include <watchdoggen.h> #include <concat.h> using namespace std; int main () { string plain; char key1[16]; char si[10]; char w[10]; char fid[20]; cout << "Enter the number of s

我试图从一个主函数调用两个函数。我的主函数代码如下:

#include <watchdoggen.h>
#include <concat.h>
using namespace std;


int main () {
    string plain;
    char key1[16];
    char si[10];
    char w[10];
    char fid[20];

    cout << "Enter the number of splits: ";
    cin >> si;
    cout << "Enter the number of watchdogs: ";
    cin >> w;
    cout << "Enter the Fid: ";
    cin >> fid;
    concat(si, w, fid);
    //cout<<"\nThe plain txt is: "<< si <<endl;
    plain = si;
    cout << "the plaintext is: ";
    cin.ignore();
    getline(cin, plain);
    cout << "Enter the Master Key: ";
    cin>>key1;
    byte* key_s = (byte*)key1;
    cout << "key: " << plain << endl;
    watchdoggen(plain,key_s);
}
我正在使用以下命令进行编译:

g++ -g3 -ggdb -O0 -DDEBUG -I/usr/include/cryptopp test4watchdoggen.cpp \
    watchdoggen.cpp concat.cpp -o test4watchdog -lcryptopp -lpthread
我需要一些帮助

海螺

#ifndef TRY_H_INCLUDED
#define TRY_H_INCLUDED

char concat(char si[],char w[],char fid[]);

#endif
用于防止两次包含同一标头:

#ifndef MY_GUARD
#define MY_GUARD
// code ...
#endif
但是,只有当每个头都有一个唯一的防护名称时,这种方法才能正常工作。在您的情况下,两个标题中的防护名称相同
TRY_H_INCLUDED
,因此包含其中一个会自动阻止包含另一个


修复方法是按照Hari Mahadevan的建议,为每个头文件提供一个唯一的include-guard名称。

欢迎使用堆栈溢出。请尽快阅读这一页。
标题中有什么?顺便说一句,它不是一个标准的头文件,但它的名字表明这就是您的
concat()
函数可能来自的地方。从您的代码来看,如果声明了输出,则不清楚
concat()
将把输出放在何处。您有一系列听起来相似但却不同的东西,在一起使用时会给您带来很多问题。为什么不使用char[]或string,但不能同时使用两者?请查看
标题中的内容。。。检查您试图调用的
concat()
函数是否存在,是否没有可能从翻译单元中删除它的
#if
语句,以及它是否位于您需要用来调用它的命名空间中。(或者——有时更好——您可以调用编译器
g++-E-DDEBUG-I/usr/include/cryptopp test4watchdoggen.cpp watchdoggen.cpp concat.cpp
,并检查预处理后的代码,以确保函数如预期的那样存在)。35;如果ndef TRY_H_include#定义TRY_H_include char concat(char si[],char w[],char-fid[])#End如果这是我的concat.h的样子,那么您的
watchdoggen.h
中是否也包含
#define TRY___
#ifndef MY_GUARD
#define MY_GUARD
// code ...
#endif