Putting using namespace std
at the top of every program is a bad habit a bad habit that you'd do well to avoid. Know when to use it and when not to (as when writing include headers). In this particular case, I happen to think it's perfectly appropriate because it's a single short program that and not a header. Some people seem to think it should never be used under any circumstance, but my view is that it can be used as long as it is done responsibly and with full knowledge of the consequences.
This is almost always wrong almost always wrong. Instead, you could make this both simpler and more correct by writing it like this:
Putting using namespace std
at the top of every program is a bad habit that you'd do well to avoid. Know when to use it and when not to (as when writing include headers). In this particular case, I happen to think it's perfectly appropriate because it's a single short program that and not a header. Some people seem to think it should never be used under any circumstance, but my view is that it can be used as long as it is done responsibly and with full knowledge of the consequences.
This is almost always wrong. Instead, you could make this both simpler and more correct by writing it like this:
Putting using namespace std
at the top of every program is a bad habit that you'd do well to avoid. Know when to use it and when not to (as when writing include headers). In this particular case, I happen to think it's perfectly appropriate because it's a single short program that and not a header. Some people seem to think it should never be used under any circumstance, but my view is that it can be used as long as it is done responsibly and with full knowledge of the consequences.
This is almost always wrong. Instead, you could make this both simpler and more correct by writing it like this:
void pushFile(const std::vector<std::string>string>& totalList, const std::stringstring& fileName);
void pushFile(std::vector<std::string> totalList, std::string fileName);
void pushFile(const std::vector<std::string>& totalList, const std::string& fileName);
Now the entire function is much cleaner, shorter and easier to read: void pushFile(const std::vectorstd::string& totalList, const std::string& fileName) { std::fstream ioFile(fileName); if (ioFile) { for (const auto &item : totalList) { ioFile << item << '\n'; } } }
void pushFile(const std::vector<std::string>& totalList,
const std::string& fileName)
{
std::fstream ioFile(fileName);
if (ioFile) {
for (const auto &item : totalList) {
ioFile << item << '\n';
}
}
}
Now the entire function is much cleaner, shorter and easier to read: void pushFile(const std::vectorstd::string& totalList, const std::string& fileName) { std::fstream ioFile(fileName); if (ioFile) { for (const auto &item : totalList) { ioFile << item << '\n'; } } }
Now the entire function is much cleaner, shorter and easier to read:
void pushFile(const std::vector<std::string>& totalList,
const std::string& fileName)
{
std::fstream ioFile(fileName);
if (ioFile) {
for (const auto &item : totalList) {
ioFile << item << '\n';
}
}
}