本文整理汇总了C++中std::ostringstream::str方法的典型用法代码示例。如果您正苦于以下问题:C++ ostringstream::str方法的具体用法?C++ ostringstream::str怎么用?C++ ostringstream::str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ostringstream
的用法示例。
在下文中一共展示了ostringstream::str方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doCommandLineProcess
// Executes the program in "batch" mode, where the user passes some command-line args
bool slamdemoApp::doCommandLineProcess()
{
// Declare the supported options.
TCLAP::CmdLine cmd("2d-slam-demo", ' ', mrpt::system::MRPT_getVersion().c_str());
TCLAP::ValueArg<std::string> arg_cfgFil("c","config","Config file to load",false,"","params.ini",cmd);
TCLAP::SwitchArg arg_nogui("n","nogui","Don't stay in the GUI, exit after the experiment.",cmd, false);
TCLAP::SwitchArg arg_norun("r","norun","Just load the config file, don't run it.",cmd, false);
#ifdef MRPT_OS_WINDOWS
CMyCmdLineOut out_buf;
cmd.setOutput(&out_buf);
#endif
vector<char*> auxArgs(argc);
for (int i=0;i<argc;i++)
{
wxString s(argv[i]);
auxArgs[i]=new char[s.size()+10];
strcpy(auxArgs[i],s.ToUTF8().data());
}
// Parse arguments:
bool res_parse = cmd.parse( argc, &auxArgs[0] );
// Free aux mem:
for (int i=0;i<argc;i++)
delete[] auxArgs[i];
if (!res_parse)
{
#ifdef MRPT_OS_WINDOWS
if (!out_cmdLine.str().empty())
wxMessageBox(_U(out_cmdLine.str().c_str()),_("2d-slam-demo"));
#endif
return false;
}
const std::string cfgFil = arg_cfgFil.getValue();
if ( !mrpt::system::fileExists(cfgFil) )
{
cerr << "The indicated config file does not exist: " << cfgFil << endl;
#ifdef MRPT_OS_WINDOWS
wxMessageBox(wxT("The indicated config file does not exist"),_("2d-slam-demo"));
#endif
return false;
}
else
{
m_option_norun = arg_norun.getValue();
if (!arg_nogui.getValue())
{
win->Show();
SetTopWindow(win);
}
try
{
DoBatchExperiments(cfgFil);
}
catch (std::exception &e)
{
cerr << e.what() << endl;
#ifdef MRPT_OS_WINDOWS
wxMessageBox(_U(e.what()),_("2d-slam-demo"));
#endif
}
}
// return false to exit the program now and NOT proceed with the GUI.
// return true to continue with the program:
return !arg_nogui.getValue();
}
示例2: check
void deallocuse1() {
check("void f(char *p) {\n"
" free(p);\n"
" *p = 0;\n"
"}");
ASSERT_EQUALS("[test.c:3]: (error) Dereferencing 'p' after it is deallocated / released\n", errout.str());
check("void f(char *p) {\n"
" free(p);\n"
" char c = *p;\n"
"}");
ASSERT_EQUALS("[test.c:3]: (error) Dereferencing 'p' after it is deallocated / released\n", errout.str());
}
示例3: check
void test1() {
check("class Fred\n"
"{\n"
"private:\n"
" unsigned int f();\n"
"public:\n"
" Fred();\n"
"};\n"
"\n"
"Fred::Fred()\n"
"{ }\n"
"\n"
"unsigned int Fred::f()\n"
"{ }");
ASSERT_EQUALS("[test.cpp:4]: (style) Unused private function: 'Fred::f'\n", errout.str());
check("#file \"p.h\"\n"
"class Fred\n"
"{\n"
"private:\n"
" unsigned int f();\n"
"public:\n"
" Fred();\n"
"};\n"
"\n"
"#endfile\n"
"Fred::Fred()\n"
"{ }\n"
"\n"
"unsigned int Fred::f()\n"
"{ }");
ASSERT_EQUALS("[p.h:4]: (style) Unused private function: 'Fred::f'\n", errout.str());
check("#file \"p.h\"\n"
"class Fred\n"
"{\n"
"private:\n"
"void f();\n"
"};\n"
"\n"
"\n"
"#endfile\n"
"\n"
"void Fred::f()\n"
"{\n"
"}");
ASSERT_EQUALS("[p.h:4]: (style) Unused private function: 'Fred::f'\n", errout.str());
// Don't warn about include files which implementation we don't see
check("#file \"p.h\"\n"
"class Fred\n"
"{\n"
"private:\n"
"void f();\n"
"void g() {}\n"
"};\n"
"\n"
"#endfile\n"
"\n"
"int main()\n"
"{\n"
"}");
ASSERT_EQUALS("", errout.str());
}
示例4:
~ExpectedStreamOutput()
{
original_stream.rdbuf(&original_streambuf);
original_stream << substituted_stream.str();
}
示例5: sizeofVoid
void sizeofVoid() {
check("void f() {\n"
" int size = sizeof(void);\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (portability) Behaviour of 'sizeof(void)' is not covered by the ISO C standard.\n", errout.str());
check("void f() {\n"
" void* p;\n"
" int size = sizeof(*p);\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (portability) '*p' is of type 'void', the behaviour of 'sizeof(void)' is not covered by the ISO C standard.\n", errout.str());
check("void f() {\n"
" void* p = malloc(10);\n"
" int* p2 = p + 4;\n"
" int* p3 = p - 1;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n"
"[test.cpp:4]: (portability) 'p' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str());
check("void f() {\n"
" void* p1 = malloc(10);\n"
" void* p2 = malloc(5);\n"
" p1--;\n"
" p2++;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n"
"[test.cpp:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str());
check("void f() {\n"
" void** p1 = malloc(10);\n"
" p1--;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" void** p1;\n"
" int j = sizeof(*p1);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" void* p1[5];\n"
" int j = sizeof(*p1);\n"
"}");
ASSERT_EQUALS("", errout.str());
// Calculations on void* with casts
check("void f(void *data) {\n"
" *((unsigned char *)data + 1) = 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f(void *data) {\n"
" *((unsigned char *)(data) + 1) = 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f(void *data) {\n"
" unsigned char* c = (unsigned char *)(data + 1);\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str());
check("void f(void *data) {\n"
" unsigned char* c = (unsigned char *)data++;\n"
" unsigned char* c2 = (unsigned char *)++data;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n"
"[test.cpp:3]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str());
check("void f(void *data) {\n"
" void* data2 = (void *)data + 1;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (portability) 'data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str());
// #4908 (void pointer as a member of a struct/class)
check("struct FOO {\n"
" void *data;\n"
"};\n"
"char f(struct FOO foo) {\n"
" char x = *((char*)(foo.data+1));\n"
" foo.data++;\n"
" return x;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (portability) 'foo.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n"
"[test.cpp:6]: (portability) 'foo.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str());
check("struct FOO {\n"
" void *data;\n"
"};\n"
"char f(struct FOO foo) {\n"
" char x = *((char*)foo.data+1);\n"
" return x;\n"
"}\n"
"char f2(struct FOO foo) {\n"
" char x = *((char*)((FOO)foo).data + 1);\n"
" return x;\n"
"}\n"
"char f3(struct FOO* foo) {\n"
//.........这里部分代码省略.........
示例6: check
void division2() {
check("void f()\n"
"{\n"
" int ivar = -2;\n"
" unsigned int uvar = 2;\n"
" return uvar / ivar;\n"
"}", true);
ASSERT_EQUALS("[test.cpp:5]: (warning, inconclusive) Division with signed and unsigned operators. The result might be wrong.\n", errout.str());
}
示例7: error
void Logger::error(std::ostringstream& stream) throw()
{
string text = stream.str();
error(text.data());
}
示例8: structmember
void structmember() {
check("struct Foo { int *p };\n"
"void f(struct Foo *foo) {\n"
" int i = foo->p;\n"
"}");
TODO_ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning a pointer to an integer is not portable.\n", "", errout.str());
}
示例9: sizeofForNumericParameter
void sizeofForNumericParameter() {
check("void f() {\n"
" std::cout << sizeof(10) << std::endl;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter.\n", errout.str());
check("void f() {\n"
" std::cout << sizeof(-10) << std::endl;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter.\n", errout.str());
check("void f() {\n"
" std::cout << sizeof 10 << std::endl;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter.\n", errout.str());
check("void f() {\n"
" std::cout << sizeof -10 << std::endl;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter.\n", errout.str());
}
示例10: always
void Logger::always(std::ostringstream& stream) throw()
{
string text = stream.str();
always(text.data());
}
示例11: checkPointerSizeof
void checkPointerSizeof() {
check("void f() {\n"
" char *x = malloc(10);\n"
" free(x);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" int *x = malloc(sizeof(*x));\n"
" free(x);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" int *x = malloc(sizeof(int));\n"
" free(x);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" int *x = malloc(sizeof(x));\n"
" free(x);\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Size of pointer 'x' used instead of size of its data.\n", errout.str());
check("void f() {\n"
" int *x = malloc(sizeof(&x));\n"
" free(x);\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Size of pointer 'x' used instead of size of its data.\n", errout.str());
check("void f() {\n"
" int *x = malloc(100 * sizeof(x));\n"
" free(x);\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Size of pointer 'x' used instead of size of its data.\n", errout.str());
check("void f() {\n"
" int *x = malloc(sizeof(x) * 100);\n"
" free(x);\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Size of pointer 'x' used instead of size of its data.\n", errout.str());
check("void f() {\n"
" int *x = malloc(sizeof *x);\n"
" free(x);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" int *x = malloc(sizeof x);\n"
" free(x);\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Size of pointer 'x' used instead of size of its data.\n", errout.str());
check("void f() {\n"
" int *x = malloc(100 * sizeof x);\n"
" free(x);\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Size of pointer 'x' used instead of size of its data.\n", errout.str());
check("void f() {\n"
" int *x = calloc(1, sizeof(*x));\n"
" free(x);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" int *x = calloc(1, sizeof *x);\n"
" free(x);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" int *x = calloc(1, sizeof(x));\n"
" free(x);\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Size of pointer 'x' used instead of size of its data.\n", errout.str());
check("void f() {\n"
" int *x = calloc(1, sizeof x);\n"
" free(x);\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Size of pointer 'x' used instead of size of its data.\n", errout.str());
check("void f() {\n"
" int *x = calloc(1, sizeof(int));\n"
" free(x);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" char x[10];\n"
" memset(x, 0, sizeof(x));\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" char* x[10];\n"
" memset(x, 0, sizeof(x));\n"
//.........这里部分代码省略.........
示例12: buffer
void Logger::buffer(std::ostringstream& stream) throw()
{
string text = stream.str();
buffer(text.data());
}
示例13: deallocThrow
void deallocThrow()
{
check("int * p;\n"
"void f(int x)\n"
"{\n"
" delete p;\n"
" if (x)\n"
" throw 123;\n"
" p = 0;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:6]: (error) Throwing exception in invalid state, p points at deallocated memory\n", errout.str());
}
示例14: info
void Logger::info(std::ostringstream& stream) throw()
{
string text = stream.str();
info(text.data());
}
示例15: trace
void Logger::trace(std::ostringstream& stream) throw()
{
string text = stream.str();
trace(text.data());
}