https://github.com/ctyd0/stringmanip
I'm new to C++, I know this is super basic but is there any logic/structure that could use improvement so far?
#String Manipulation
15 messages · Page 1 of 1 (latest)
having public: that many times in manip.h makes the code harder to read
since you usually only expect those when the access level changes
It is usually preferred to have getters return members
selection should at the very least be a bool
though it would be better to change the structure so you dont need it at all
I see, thank you! I'll try and refactor
I find your function naming completely misleading, everything returns void and the names are toBinary, getWords and so on... get should return something toXX should maybe take a reference... also mark stuff stuff as const like
void getWordCount() const {
std::cout << "Total amount of words modified: " << wordCount << std::endl;
}
no member variables are changed here
reversedWord = temp + reversedWord; this can be just +=
👍
nice .gitignore, might yoink
For naming - if the function prints something, a better name would be "printXXX()"
Hello,
Just for readability, it is better to rename member data by a prefix like m_ or m , this will help to avoid using this inside the class itself (see file manip.hpp line 15):
this->wordVector = wordVector;
It will be better to use const std::string& in the for-each loop as the function toString only print words into the standard-output, thus avoiding copy semantics.
(see file manip.h line 29)
In line 34 from the same file, you can change the implementation of void reverseWords() function to use std::reverse from <algorithm> standard library.