В приведенном ниже коде if (fork() == 0)
& if (!request.compare("") == 0)
не влияет
/* Loop forever */
while (1)
{
/* Accept a client connection */
clientFd = accept (serverFd, clientSockAddrPtr, (socklen_t*)&clientLen);
//Fork child
//if (fork() == 0)
{
while(1)
{ //Reads the client
string request = read_Request (clientFd);
bool found = false;
string response="Error !!! Country not found";
//if (!request.compare("") == 0)
{
for(vector<Country>::iterator it = countryData.begin(); it != countryData.end(); it++)
{
if(request.compare(it -> name) == 0)
{
string countryName = it -> name;
response += "\n";
response += it -> name;
response += " TLD Code";
response += ((countryName).append(" TLD Code"));
response += ": ";
response += it -> TLDCode;
response += "\n";
countryName = it -> name;
response += it -> name;
response += " FIPS104 Country Code";
response += ((countryName).append(" FIPS104 Country Code"));
response += ": ";
response += it -> FIPS104CountryCode;
response += "\n";
countryName = it -> name;
response += it -> name;
response += " ISO2 Country Code";
response += ((countryName).append(" ISO2 Country Code"));
response += ": ";
response += it -> ISO2CountryCode;
response += "\n";
countryName = it -> name;
response += it -> name;
response += " population";
response += ((countryName).append(" population"));
response += ": ";
response += it -> population;
response += "\n";
found = true;
}
}
}
write (clientFd, response.c_str(), strlen (response.c_str()) + 1);
}
}
close (clientFd);
}
}
Строковый ответ печатается в случае как истинных, так и ложных.
Любые предложения, пожалуйста
Итак, здесь вы назначаете строку для response
переменной String response="Error !!! Country not found";
то здесь вы конкатенируете другую строку в ответ, которая дает вам свой результат.
response += "\n";
response += it -> name;
т.е. Ошибка !!! Страна не найдена +\n + it-> имя и т.д.
Во-вторых, как @ChrisJ.Kiick сказал, что у вас есть таинственный тип String, который не является частью языка c