-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_parse_str.cpp
More file actions
44 lines (36 loc) · 1.46 KB
/
test_parse_str.cpp
File metadata and controls
44 lines (36 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*****************************************************************//**
* \file test_parse_str.cpp
* \brief Demonstration of function to parse a comma-separated string
* into integers and store them in a std::vector<int>.
*
* To compile and run this file on Windows:
* $ g++ -o test_parse_str.exe .\test_parse_str.cpp -std=c++11
* $ .\test_parse_str.exe
*
* \author Xuhua Huang
* \date October 2021
*********************************************************************/
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <vector>
// Customized utility library
#include "parse.hpp"
#include "print_vec.hpp"
int main() {
/* Split a comma-separated string to an array of integers. */
std::string str;
// std::cin >> str;
str = "1,23,456,789"; // test with a comma as delimiter
std::vector<int> integers = util::parse::parse_str<int>(str);
util::vector::print_vec<int>(integers);
std::string cell_phone = "541-952-1655"; // test with a dash as delimiter
std::vector<int> cell_to_ints = util::parse::parse_str<int>(cell_phone, '-');
util::vector::print_vec<int>(cell_to_ints);
/* Split a comma-separated string to an array of characters. */
const std::string name = "Huang,Xuhua";
std::vector<std::string> spell_name = util::parse::parse_str<std::string>(name);
util::vector::print_vec<std::string>(spell_name);
system("pause");
return EXIT_SUCCESS;
}