瀏覽代碼

string magic

Former-commit-id: 75006a1b4f1b57389512d91a386019e05e07640c
Alec Jacobson (jalec 12 年之前
父節點
當前提交
6548d97306
共有 2 個文件被更改,包括 22 次插入0 次删除
  1. 11 0
      include/igl/C_STR.h
  2. 11 0
      include/igl/STR.h

+ 11 - 0
include/igl/C_STR.h

@@ -0,0 +1,11 @@
+#ifndef C_STR_H
+#define C_STR_H
+// http://stackoverflow.com/a/2433143/148668
+// Suppose you have a function:
+//   void func(const char * c);
+// Then you can write:
+//   func(C_STR("foo"<<1<<"bar"));
+#include <string>
+#include <sstream>
+#define C_STR(X) static_cast<std::ostringstream&>(std::ostringstream().seekp(0) << X).str().c_str()
+#endif

+ 11 - 0
include/igl/STR.h

@@ -0,0 +1,11 @@
+#ifndef STR_H
+#define STR_H
+// http://stackoverflow.com/a/2433143/148668
+#include <string>
+#include <sstream>
+// Suppose you have a function:
+//   void func(std::string c);
+// Then you can write:
+//   func(STR("foo"<<1<<"bar"));
+#define STR(X) static_cast<std::ostringstream&>(std::ostringstream().seekp(0) << X).str()
+#endif