Inclure C++ Fichier vers un autre Fichier C++

Je suis havin un problème y compris dans mes fichiers. J'ai 3 fichiers C++ et toutes dans l'int main(void).

Le problème est que chaque fois que je comprennent 1 d'entre eux il est dit que:

fonction " int main(void)' a déjà un corps

mais si je vais supprimer l'int main(void) à deux autres fichier C++ c'erreurs invite maintenant.

'one or more multiply defined symbols found'

"class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl convertInt(int)" (?convertInt@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) already defined in FormatPosDataXml().obj

"class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl convertInt(int)" (?convertInt@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) already defined in FormatPosDataXml().obj    

et ainsi de suite

c'est un code que j'ai:

FormatPosDataXml().rpc

#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cstring>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
using namespace std;
#define nextline '\n'
inline bool TextContains(char *text, char ch) {
while ( *text ) {
if ( *text++ == ch )
return true;
}
return false;
}
void Split(char *text, char *delims, vector<string> &words) {
int beg;
for (int i = 0; text[i]; ++i) {
while ( text[i] && TextContains(delims, text[i]) )
++i;
beg = i;
while ( text[i] && !TextContains(delims, text[i]) )
++i;
words.push_back( string(&text[beg], &text[i]) );
}
}
string convertInt(int number)
{
stringstream ss;//create a stringstream
ss << number;//add number to the stream
return ss.str();//return a string with the contents of the stream
}
string dateFormatChecker(const char *date){
string strdate=date;
char getdate[50];
strcpy_s(getdate, strdate.c_str());
vector<string> checkdate;
Split( getdate, "-", checkdate );
int year, month, day;
year=atoi(checkdate[0].c_str());
month=atoi(checkdate[1].c_str());
day=atoi(checkdate[2].c_str());
string checkyear, checkmonth, checkday, checkhour, checkminute, checksecond;
checkyear = convertInt(year);
if(month<10){
checkmonth = "0" + convertInt(month);
}
else{
checkmonth = convertInt(month);
}
if(day<10){
checkday = "0" + convertInt(day);
}
else{
checkday = convertInt(day);
}
/*
cout << checkdate[0] << ' ' << checkyear << '\n'
<< checkdate[1] << ' ' << checkmonth << '\n'
<< checkdate[2] << ' ' << checkday << '\n';
*/
if (checkyear.size() != checkdate[0].size()||
checkmonth.size() != checkdate[1].size()||
checkday.size() != checkdate[2].size()){
return "";
}
return date;
}
string dateandtimeFormatChecker(const char *dateandtime){
string strdate=dateandtime;
char getdateandtime[50];
strcpy_s(getdateandtime, strdate.c_str());
vector<string> checkdateandtime;
Split( getdateandtime, "-: ", checkdateandtime );
int year, month, day, hour, minute, second;
year=atoi(checkdateandtime[0].c_str());
month=atoi(checkdateandtime[1].c_str());
day=atoi(checkdateandtime[2].c_str());
hour=atoi(checkdateandtime[3].c_str());
minute=atoi(checkdateandtime[4].c_str());
second=atoi(checkdateandtime[5].c_str());
string checkyear, checkmonth, checkday, checkhour, checkminute, checksecond;
checkyear = convertInt(year);
if(month<10){
checkmonth = "0" + convertInt(month);
}
else{
checkmonth = convertInt(month);
}
if(day<10){
checkday = "0" + convertInt(day);
}
else{
checkday = convertInt(day);
}
if(hour<10){
checkhour = "0" + convertInt(hour);
}
else{
checkhour = convertInt(hour);
}
if(minute<10){
checkminute = "0" + convertInt(minute);
}
else{
checkminute = convertInt(minute);
}
if(second<10){
checksecond = "0" + convertInt(second);
}
else{
checksecond = convertInt(second);
}
if (checkyear.size() != checkdateandtime[0].size()||
checkmonth.size() != checkdateandtime[1].size()||
checkday.size() != checkdateandtime[2].size()||
checkhour.size() != checkdateandtime[3].size()||
checkminute.size() != checkdateandtime[4].size()||
checksecond.size() != checkdateandtime[5].size()){
return "";
}
//cout << year<< '/' << month << '/' << day << ' ' << hour << ':' << minute << ':' << second << '\n';
return dateandtime;     
}
string transaction (const char * SequenceNumber, const char * RetailStoreID, const char * WorkStationID, const char * BusinessDayDate, const char * BeginDateTime, const char * StartTransTime, const char * EndTransTime, const char * EndDateTime, const char * RawData){
string output;
string bdd, bdt, stt, ett, edt;
bdd = dateFormatChecker(BusinessDayDate);
bdt = dateandtimeFormatChecker(BeginDateTime);
stt = dateandtimeFormatChecker(StartTransTime);
ett = dateandtimeFormatChecker(EndTransTime);
edt = dateandtimeFormatChecker(EndDateTime);
cout << "<Transaction>" << "\n\t<RetailStoreID>"
<< RetailStoreID   << "</RetailStoreID>\n\t<WorkStationID>"
<< WorkStationID   << "</WorkStationID>\n\t<SequenceNumber>"
<< SequenceNumber  << "</SequenceNumber>\n\t<BusinessDayDate>"
<< bdd             << "</BusinessDayDate>\n\t<BeginDateTime>"
<< bdt             << "</BeginDateTime>\n\t<StartTransTime>"
<< stt             << "</StartTransTime>\n\t<EndTransTime>"
<< ett             << "</EndTransTime>\n\t<EndDateTime>"
<< edt             << "</EndDateTime>\n\t<RawData>"
<< RawData         << "</RawData>\n</Transaction>";
output = _getch();
return output; 
}
int main(void) {
vector<string> words;
char * data = "1,1,SAMPLE,2010-01-31,2011-01-31 14:09:10,2011-01-31 14:42:10,2011-01-31 14:42:10,2011-01-31 14:42:10,JELLY-O RUBBERB\n\r               13.25V.¶üÁËO";
Split( data, ",", words );
char SN[11], RSI[200], WSI[200], BDD[100], BDT[100], STT[100], ETT[100], EDT[100], RD[100];
strcpy_s(SN, words[0].c_str());
strcpy_s(RSI, words[1].c_str());
strcpy_s(WSI, words[2].c_str()); 
strcpy_s(BDD, words[3].c_str());
strcpy_s(BDT, words[4].c_str());
strcpy_s(STT, words[5].c_str());
strcpy_s(ETT, words[6].c_str());
strcpy_s(EDT, words[7].c_str());
strcpy_s(RD, words[8].c_str());
string PosData;
PosData = transaction(SN,RSI,WSI,BDD,BDT,STT,ETT,EDT,RD);
/* Checker 
for (int i = 0; i != words.size(); i++){
cout << words[i] << nextline;
}
cout << SN << nextline << RSI << nextline << WSI << nextline << BDD << nextline << BDT << nextline << STT << nextline << ETT << nextline << EDT << nextline << RD; 
*/
return 0;
}

FSNPC.cpp

#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cstring>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include "FormatPosDataXml().cpp"
using namespace std;
string getstring(string holder){
if (holder == "" || holder.size()>100){
exit(1);
}
int i=0,ch=0;
int size;
char charInput[100];
strcpy_s(charInput, holder.c_str());
size = strlen(charInput);
#define DATA_LENGTH 100
#define BUFFER_LENGTH (DATA_LENGTH)
char Buffer[BUFFER_LENGTH];
while (i < DATA_LENGTH) {
Buffer[i++] = charInput[i];
Buffer[i] = '\0';
if(size == i){
break;
}
}
holder = Buffer;
strcpy_s(charInput, holder.c_str());
size = strlen(charInput);
i = 0;
for(int j = 0;j<size;j++)
{
if (charInput[j] < 2) 
{
if (charInput[j+i] > 2 && charInput[j+i] != 17){
charInput[j] = charInput[j+i];
charInput[j+i]='\0';
i=0;
}
else{
i++;
j--;
}
}else if (charInput[j] == 17) 
{
if (charInput[j+i] > 2 && charInput[j+i] != 17){
charInput[j] = charInput[j+i];
charInput[j+i]='\0';
i=0;
}
else{
i++;
j--;
}
}
}
size = strlen(charInput);
for(int remove = 0; remove<size ;remove++)
{
if (charInput[remove] < 2 || charInput[remove] == 17) 
{
charInput[remove]='\0';
}
}
string handler;
handler = charInput;
handler = handler.substr(0, handler.length() - 1);
return (handler);
}
/*
int main(void){
string final;
string input = "JELLY-O RUBBERB\n\r               13.25V.¶üÁË0";
string input2 = "STIÁËCK-O CHOCO\n\r               10.52C.ÁË0¶ü";
string input3 = "STICÁËK-O VANILLA\n\r               10.52C.ÁË0¶ü";
final = getstring(input)+ "\n" +getstring(input2)+ "\n"
+getstring(input3);
cout<<final;
_getch();
return 0;
}*/

keypress.cpp

#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <string>
#include "FormatPosDataXml().cpp"
using namespace std;
int c;
char temp[256];
char getkeypress(char c){
if (c==0x1b){
exit(1);
}
else if (c==0||c==224)        
{
c = _getch();
if (c==0x3b){
cout << "You typed: F1\n";
}
else if(c==0x3c){
cout << "You typed: F2\n";
}
else if(c==0x3d){
cout << "You typed: F3\n";
}
else if(c==0x3e){
cout << "You typed: F4\n";
}
else if(c==0x3f){
cout << "You typed: F5\n";
}
else if(c==0x40){
cout << "You typed: F6\n";
}
else if(c==0x41){
cout << "You typed: F7\n";
}
else if(c==0x42){
cout << "You typed: F8\n";
}
else if(c==0x43){
cout << "You typed: F9\n";
}
else if(c==0x44){
cout << "You typed: F10\n";
}
else if(c==133){
cout << "You typed: F11\n";
}
else if(c==134){
cout << "You typed: F12\n";
}
}
else
{ 
while((cin.getline(temp, sizeof(temp), '\n'))&&(temp!="")){
cout << "You typed:" << temp << '\n';
break;
}
}
}
/*  
int main(void){
while (c^=0x1b){
cout<<"Press any key:\n";
c = getkeypress(_getch());
} 
_getch();
return 0;
}
*/

comment pourrais-je relier tous ces fichiers. Je veux qu'ils soient d'une bibliothèque. Comment pourrais-je faire alors?

  • Ce code est beaucoup trop difficile à lire. Peut-être vous ou quelqu'un d'autre peut le formater mieux. Aussi, vous ne devez pas afficher complet des exemples de code en question. Essayez la déshabiller pour le strict minimum de code nécessaire pour générer l'erreur.
  • Pourquoi voulez-vous inclure un fichier cpp dans un autre? Ce que vous essayez d'accomplir en termes abstraits - ne pense pas de code pour l'instant)?
  • s'il vous plaît accepter mon montage. Votre code sera un peu plus lisible.
  • Vous devriez poster complète des exemples de code en question! Vous devez également réduire un cas de test pour une taille gérable avant de poster. (J'ai "voté" sur votre "modifier suggestion", et il ne me laisse pas le modifier jusqu'à ce que soit approuvé (besoin de plus de votes), ou rejeté; je ne suis pas familier avec ce système.)
  • Nurk Désolé, je voulais dire ... eh bien ... ne pas publier de trois cent lignes de code lorsque votre question est à propos d'une erreur de l'éditeur de liens. Merci pour le vote. Je ne suis pas sûr de savoir comment il fonctionne, sauf que je sais que l'original, le demandeur peut immédiatement approuver la modification.
  • Nurk: je suppose que mon vote pour approuver "le mettre sur le dessus", pour ainsi dire. Malheureusement, alors que le code est beaucoup plus formatés que maintenant (merci @mgiuca), il est encore juste un gros tas de code, n'ayant rien à nous dire ce qu'il veut vraiment...
  • Je suis complètement d'accord; je ne veux pas que les gens comme Andro d'afficher les deux lignes de code en dehors de tout contexte en suivant "vous ne devriez pas le post des exemples de code".