MRPT  1.9.9
printf_vector.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/core/format.h>
12 #include <cstdio>
13 #include <string>
14 #include <vector>
15 
16 namespace mrpt::containers
17 {
18 /** \addtogroup
19  * @{ */
20 
21 /** Generates a string for a vector in the format [A,B,C,...] to std::cout, and
22  * the fmt string for <b>each</b> vector element. */
23 template <typename VEC>
24 std::string sprintf_vector(const char* fmt, const VEC& V)
25 {
26  std::string ret = "[";
27  const size_t N = V.size();
28  for (size_t i = 0; i < N; i++)
29  {
30  ret += format(fmt, V[i]);
31  if (i != (N - 1)) ret += ",";
32  }
33  ret += "]";
34  return ret;
35 }
36 
37 /** Prints a vector in the format [A,B,C,...] to std::cout, and the fmt string
38  * for <b>each</b> vector element. */
39 template <typename T>
40 void printf_vector(const char* fmt, const std::vector<T>& V)
41 {
42  ::fputs(sprintf_vector(fmt, V).c_str(), stdout);
43 }
44 
45 /** @} */ // end of grouping
46 } // namespace mrpt::containers
void printf_vector(const char *fmt, const std::vector< T > &V)
Prints a vector in the format [A,B,C,...] to std::cout, and the fmt string for each vector element...
Definition: printf_vector.h:40
GLsizei const GLchar ** string
Definition: glext.h:4116
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
std::string sprintf_vector(const char *fmt, const VEC &V)
Generates a string for a vector in the format [A,B,C,...] to std::cout, and the fmt string for each v...
Definition: printf_vector.h:24



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019