NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
fromstring.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <sstream>
31
32#include "NumCpp/NdArray.hpp"
33
34namespace nc
35{
36 //============================================================================
37 // Method Description:
46 template<typename dtype>
47 NdArray<dtype> fromstring(const std::string& inStr, const char inSep = ' ')
48 {
50
51 std::istringstream inputStream(inStr);
52 auto values = std::vector<dtype>{};
53 dtype value{};
54 for (std::string segment; std::getline(inputStream, segment, inSep);)
55 {
56 if (!inputStream.fail())
57 {
58 std::istringstream segmentStream(segment);
59 while (segmentStream >> value)
60 {
61 if (!inputStream.fail())
62 {
63 values.push_back(value);
64 }
65 }
66 }
67 }
68
69 return NdArray<dtype>(values);
70 }
71} // namespace nc
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition StaticAsserts.hpp:39
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:135
Definition Cartesian.hpp:39
NdArray< dtype > fromstring(const std::string &inStr, const char inSep=' ')
Definition fromstring.hpp:47