Question
C++ ToString Objective:Learn basic use of templates. In this exercise you will need to implement different overloaded versions of functionToStringthat returns the contents of an
ToString
Objective:Learn basic use of templates.
In this exercise you will need to implement different overloaded versions of functionToStringthat returns the contents of an container as a string. Any type of sequential container should be compatible, i.e. you need to use the container through template.
- One version of the function gets a container type as a parameter, in which case it will return the contents of the whole container in a string.
- Another version of the function gets beginning and ending iterators, in which case the range between iterators is printed.
- In addition, if given a string, theToStringshould just return the string inside double quotes: "somestring".
- When a string is given as two iterators (e.g., ToString(str.begin(), str.end()), it will be printed as sequence of characters: { f, o, o }
Apart from the single string case, the function should return the container items as comma separated list inside brackets. For example, in the case of string container elements, it would return something like the following (spaces are significant):
{ foo, bar, baz }
main.cpp
#include "to_string.hpp"
#include
#include
int main() {
std::string s = "foobar";
std::cout (s)
std::cout
std::set v;
v.insert(1.23);
v.insert(4.56);
v.insert(7.89);
std::cout
std::cout
}
Write fill to_string.hpp
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started