Top Page > C++ �����W > �T���v��


C++ �����W - �T���v��


reg_manager

C++ with reg_manager�F
reg_manager rm;
string s= "<h1>Title</h1>Hello.";
if (rm.search(s, "<H1>(.*?)</H1>", "i"))
  cout<<rm.str(1)<<endl; // "Title"�Əo��
rm.replace(s, "<h1>(.*?)</h1>", "<p>\\1</p>", "g");
cout<<s<<endl; // "<p>Title</p>Hello."�Əo��
Perl�F
$s= "<h1>Title</h1>Hello.";
if ($s=~ /<H1>(.*?)<\/H1>/i){
  print "$1\n";
}
$s=~ s/<h1>(.*?)<\/h1>/<p>\1<\/p>/g;
print "$s\n";


socket

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;
}


arg_parser

int main(int argc, char** argv){
  arg_parser ap(argc, argv, "o");
  if (ap.has_option('a')) cout<<"-a���w�肳�ꂽ"<<endl;
  if (ap.has_option('o')) cout<<"-o�I�v�V�����̈�����"<<ap.option_arg('o')<<endl;
  cout<<"�I�v�V�����ȊO�̈����F"<<endl;
  for (int i= 0; i<ap.normal_argc(); ++i) cout<<ap.normal_argv(i)<<endl;
  return 0;
}


simple_streambuf

//Windows��OutputDebugString()�ŏo�͂���streambuf
class DebugStreambuf: public simple_ostreambuf{
protected:
  virtual bool put(const std::string& s){
    OutputDebugString(s.c_str());
    return true;
  }
};
 
//Windows��OutputDebugString()�ŏo�͂���ostream
class DebugOStream: public ostream
{
public:
  DebugOStream(): ostream(0){rdbuf(&sbuf);}
  ~DebugOStream(){rdbuf(0);}
private:
  DebugStreambuf sbuf;
};


singleton_ptr

class Foo{
public:
  void f(){ … }
private:
  Foo(){ … }
  Foo(const Foo&);
  ~Foo(){ … }
  friend class gimite::singleton_ptr<Foo>;
};
static gimite::singleton_ptr<Foo> pfoo;

 
�i�����pfoo->f()�ȂǂƂł���j


*1  �\�[�X�擪�Ɉȉ��̋L�q���K�v�ł��B
#include <gimite/�`.h>
using namespace std;
using namespace gimite;


�T���v�� < C++ �����W < TopPage