003
21.08.2005, 15:26 Uhr
(un)wissender
Niveauwart
|
Ah, Parameterübergabe also. Hie rmal ein Bsp. das du aber noch für dich anpassen musst.
C++: |
#include <algorithm> #include <iostream> #include <iterator> #include <string> #include <vector> #include <map>
// Map von Language Strings typedef std::map<std::string,std::string> cgi_all_ext;
//Vector für die gefundenen php-extensions. typedef std::vector<std::string> cgi_php_ext;
void readinextensions(cgi_all_ext &map); const cgi_php_ext giveexecute(const cgi_all_ext &map);
int main() { cgi_all_ext cgi_ext; // hold all extions to be execute as a cgi readinextensions(cgi_ext); cgi_php_ext cgi_vec = giveexecute(cgi_ext); std::cout << "Found php-extensions:\n"; std::copy(cgi_vec.begin(), cgi_vec.end(), std::ostream_iterator<std::string>(std::cout, "\n")); }
void readinextensions(cgi_all_ext &map) { typedef std::pair<std::string, std::string> my_pair; map.insert(my_pair("0", "php=c:\\php-cgi.exe")); map.insert(my_pair("1", "php=c:\\php-cgi1.exee")); map.insert(my_pair("2", "c++=c:\\c++-cgi.exe")); map.insert(my_pair("3", "c++=c:\\c++-cgi1.exe")); }
const cgi_php_ext giveexecute(const cgi_all_ext &map) { cgi_php_ext vec; const std::string EXT = "php="; typedef std::map<std::string,std::string>::const_iterator map_iter; for(map_iter i = map.begin(); i != map.end(); ++i) { std::string value = i->second; std::string::size_type index; if((index = value.find(EXT)) != std::string::npos && index + 1 + EXT.length() < value.length()) { vec.push_back(value.substr(index + EXT.length(), value.length())); } } return vec; }
|
-- Wer früher stirbt ist länger tot. |