1
0
LearningCPP/main.cpp

51 lines
1.1 KiB
C++

#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using string = std::string;
using svector = std::vector<string>;
string prompts(const string&,bool*);
void sortVStringsAsc(svector &v);
int main() {
svector inputs;
bool s{true};
while (s) {
auto inp = prompts("Enter a string (Invalid to begin processing): ",&s);
if (s) inputs.push_back(inp);
}
sortVStringsAsc(inputs);
for (const auto &c : inputs) std::cout << c << "\n";
return 0;
}
void sortVStringsAsc(svector &v) {
sort(v.begin(), v.end(), [] (const string &x, const string &y) {return x.length() < y.length();});
}
double sumList(const std::vector<double> &l) {
double sum = 0.0;
for (const auto &c : l) sum += c;
return sum;
}
class A {
std::vector<string> s;
};
string prompts(const string &message, bool *success) {
string tr{""};
*success = false;
std::cout << message;
if (!(std::cin >> tr)) {
std::cin.clear();
std::cin.ignore();
return "";
}
*success = true;
return tr;
}