Эх сурвалжийг харах

string magic

Former-commit-id: 75006a1b4f1b57389512d91a386019e05e07640c
Alec Jacobson (jalec 12 жил өмнө
parent
commit
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