1
0
LearningCPP/main.cpp

85 lines
1.5 KiB
C++

#include <iostream>
#include <list>
#include <algorithm>
#include <map>
#include <iomanip>
using string = std::string;
using slist = std::list<string>;
//Place in header!
template <typename T>
void printm(T m){
std::cout << m;
}
template <typename T>
void printlm(T m){
printm(m);
printm("\n");
}
int prompti(string,bool*);
int prompti(string,bool*);
string prompts(string,bool*);
int main() {
printlm("Parse comma deliminated list:");
bool s {};
slist lst {};
auto v = prompts("Enter the string: ", &s);
if (!s) {
printlm("Error, No Data!");
return -1;
}
auto comma = find(v.cbegin(),v.cend(),',');
lst.push_back(string(v.cbegin(),comma));
do {
auto start = ++comma;
comma = find(start,v.cend(),',');
lst.push_back(string(start, comma));
} while(comma != v.cend());
printlm("All entries:");
for (const auto c : lst) printlm(c);
return 0;
}
int prompti(string message, bool *status) {
int tr {};
*status = false;
std::cout << message;
if (!(std::cin >> tr)){
std::cin.clear();
std::cin.ignore();
return 0;
}
*status = true;
return tr;
}
double promptd(string message, bool *status) {
double tr {};
*status = false;
std::cout << message;
if (!(std::cin >> tr)){
std::cin.clear();
std::cin.ignore();
return 0.0;
}
*status = true;
return tr;
}
string prompts(string message, bool *status) {
string tr {""};
*status = false;
std::cout << message;
if (!(std::cin >> tr)){
std::cin.clear();
std::cin.ignore();
return "";
}
*status = true;
return tr;
}