Hej ludzie ! Mały błąd jest w programie i nie wiem gdzie oraz nie wiem dlaczego. Pomoże ktoś zrozumieć ? :) Opis tak na szybko initials to miała być funkcja, która otrzymuje stałą referencję łańcucha i ma i ma zwrócić/wypisać pierwsze litery kolejnych słów. Można korzystać tylko z header cctype i string.
#include <iostream>
#include <cctype>
#include <string>
void initials(const std::string &);
int main() {
std::cout << initials("Mya Diana Luiidor") << std::endl;
std::cout << initials(std::string("Stephan Stive Silver")) << std::endl;
}
void initials(const std::string &str) {
if(!str.empty()){
if(str[0] != ' ')
std::cout << str[0];
for(int i = 0; i<str.length();i++) {
if(str[i] == ' ' && str[i] != '\0')
std::cout << str[i+1];
}
}
std::cout << std::endl;
}