1
0
LearningCPP/main.cpp

85 lines
1.5 KiB
C++
Raw Permalink Normal View History

2022-10-14 09:27:47 +01:00
#include <iostream>
2022-10-28 10:11:47 +01:00
#include <list>
2022-11-04 11:58:21 +00:00
#include <algorithm>
#include <map>
2022-10-19 09:33:42 +01:00
#include <iomanip>
2022-10-14 09:27:47 +01:00
using string = std::string;
using slist = std::list<string>;
2022-10-14 09:27:47 +01:00
2022-10-28 09:43:51 +01:00
//Place in header!
2022-10-19 09:33:42 +01:00
template <typename T>
void printm(T m){
2022-10-14 09:27:47 +01:00
std::cout << m;
}
2022-10-19 09:33:42 +01:00
template <typename T>
void printlm(T m){
2022-10-14 09:27:47 +01:00
printm(m);
printm("\n");
}
2022-10-28 09:43:51 +01:00
int prompti(string,bool*);
2022-11-04 12:22:52 +00:00
int prompti(string,bool*);
string prompts(string,bool*);
2022-10-19 09:33:42 +01:00
int main() {
printlm("Parse comma deliminated list:");
2022-11-04 12:22:52 +00:00
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));
2022-11-04 12:22:52 +00:00
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);
2022-10-19 09:33:42 +01:00
return 0;
2022-10-14 09:27:47 +01:00
}
2022-10-28 09:43:51 +01:00
int prompti(string message, bool *status) {
int tr {};
2022-10-19 09:33:42 +01:00
*status = false;
2022-10-14 09:27:47 +01:00
std::cout << message;
2022-10-19 09:33:42 +01:00
if (!(std::cin >> tr)){
2022-10-14 09:27:47 +01:00
std::cin.clear();
std::cin.ignore();
2022-10-19 09:33:42 +01:00
return 0;
2022-10-14 09:27:47 +01:00
}
2022-10-19 09:33:42 +01:00
*status = true;
2022-10-14 09:27:47 +01:00
return tr;
}
2022-10-19 09:33:42 +01:00
2022-10-28 10:11:47 +01:00
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;
2022-10-28 10:11:47 +01:00
}