reg_manager rm; string s= "<h1>Title</h1>Hello."; if (rm.search(s, "<H1>(.*?)</H1>", "i")) cout<<rm.str(1)<<endl; // "Title"と出力 rm.replace(s, "<h1>(.*?)</h1>", "<p>\\1</p>", "g"); cout<<s<<endl; // "<p>Title</p>Hello."と出力 |
$s= "<h1>Title</h1>Hello."; if ($s=~ /<H1>(.*?)<\/H1>/i){ print "$1\n"; } $s=~ s/<h1>(.*?)<\/h1>/<p>\1<\/p>/g; print "$s\n"; |
int main()
{
gimite::startup_socket();
{
gimite::socket_stream sst("www.google.com", 80);
if (!sst){
std::cerr << "Failed to connect." << std::endl;
}else{
sst << "GET / HTTP/1.0\r\n\r\n";
std::string s;
while (std::getline(sst, s))
std::cout << s << std::endl;
}
}
gimite::cleanup_socket();
return 0;
}
int main()
{
gimite::startup_socket();
{
gimite::server_stream_socket server(12345);
if (!server){
std::cerr << "Failed to bind socket." << std::endl;
}else{
while (true){
gimite::socket_t s= server.accept();
gimite::socket_stream sst(s);
char c;
while (sst.get(c))
sst << c;
}
}
}
gimite::cleanup_socket();
return 0;
}
//WindowsのOutputDebugString()で出力するstreambuf
class DebugStreambuf: public simple_ostreambuf{
protected:
virtual bool put(const std::string& s){
OutputDebugString(s.c_str());
return true;
}
};
//WindowsのOutputDebugString()で出力するostream
class DebugOStream: public ostream
{
public:
DebugOStream(): ostream(0){rdbuf(&sbuf);}
~DebugOStream(){rdbuf(0);}
private:
DebugStreambuf sbuf;
};
class Foo{
public:
void f(){ … }
private:
Foo(){ … }
Foo(const Foo&);
~Foo(){ … }
friend class gimite::singleton_ptr<Foo>;
};
static gimite::singleton_ptr<Foo> pfoo;
(これでpfoo->f()などとできる)
*1 ソース先頭に以下の記述が必要です。
#include <gimite/〜.h>
using namespace std;
using namespace gimite;