1
0

String vector tester.

This commit is contained in:
Captain ALM 2023-08-20 22:19:14 +01:00
parent 798006c8d0
commit 891ee1959a
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1

View File

@ -1,42 +1,49 @@
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <random>
#include <chrono>
class A {
public:
A() {
std::cout << "Class A Created\n";
}
virtual ~A() {
std::cout << "Class A Destroyed\n";
}
};
using string = std::string;
using svector = std::vector<string>;
class B {
public:
B() {
std::cout << "Class B Created\n";
}
~B() {
std::cout << "Class B Destroyed\n";
}
};
string prompts(const string&,bool*);
void sortVStringsAsc(svector &v);
class C : public A {
B b{};
public:
C() {
std::cout << "Class C Created\n";
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);
}
virtual ~C() {
std::cout << "Class C Destroyed\n";
}
};
int main()
{
A v{};
B w{};
C x{};
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;
}