對不起超新手問題。我不熟悉C++和任何類型的編程,但是我創建了這些程序來讀取用戶輸入,然後讀取它的命令和文件。我想包含文件a.h,但是我遇到了麻煩。它告訴我,我的函數main被重新定義了,但是當我把它拿出來時,它會吐出更多的錯誤。我正在考慮可能是否有其他陳述?任何建議讓我去?有沒有一種方法可以將我的文件包含在C++中?
文件名tryout.cpp
#include <iostream>
#include <string.h>
#include "a.h"
using namespace std;
int main()
{
string cmd,command,file1,file2;
cout << "prompt<<";
cin >> cmd;
int len = cmd.length();
int temp = cmd.find('<');
command = cmd. substr(0,temp);
cout << "COMMAND: " << command << "\n";
cout << "File Redirection: " << cmd.at(temp) << "\n";
int temp1 = cmd.find('>');
file1 = cmd.substr(temp+1,temp1-temp-1);
cout << "FILE: " << file1 << "\n";
cout << "File Redirection: " << cmd.at(temp1) <<"\n";
file2 = cmd.substr(temp1+1, len-1);
cout << "File: " << file2 <<"\n";
return 0;
}
文件名 「A.H」
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
string cmd,command1,command2,command3;
cout << "prompt<<";
cin >> cmd;
int len = cmd.length();
int temp = cmd.find('|');
command1 = cmd.substr(0,temp);
cout << "COMMAND: " << command1 << "\n";
cout << "PIPE: " << cmd.at(temp) << "\n";
command2 = cmd.substr(temp+1,len-1);
cout << "COMMAND: " << command2 << "\n";
cout << "PIPE: " << cmd.at(temp) << "\n";
command3 = cmd.substr(temp+2,len-2);
cout << "COMMAND: " << command3 << "\n";
return 0;
}
這種錯誤信息以哪種方式不清楚。你的頭文件中實際上有'main()'的定義。你想實現什麼? –
我毫不猶豫地建議這有[XY問題]的非常強烈的氣味(http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)。 – WhozCraig
你爲什麼想要這樣做? – Galik