I had a a problem in implementing a Multiple Source File
My function is like this:
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;
ss << number;
return ss.str();
}
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);
}
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, checkm开发者_运维百科onth, 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 "";
}
return dateandtime;
}
string FormatPosDataXml (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;
}
string getInput(char *data){
vector<string> words;
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 = FormatPosDataXml(SN,RSI,WSI,BDD,BDT,STT,ETT,EDT,RD);
return PosData;
}
But whenever I put it in the header file like this :
string getInput(char *data);
I always get plenty of errors like undeclared identifier, int string redefinition and so on...
Anyone can you help me?
I think the order of header #includes might be the source of the problem.
Regarding this error:
'string' is not a valid template type argument for parameter '_Ty'
and
ambiguous symbol 'std::vector'
Are you being consistent with your usage of "std::" versus "using namespace std;"?
tnx for the information guys.. i finally got the right codes.
first i must put headers on the function so that it wont prompt some errors.
THen I will remove the usual header except the header that i made. and then I got it...
精彩评论