Soooo... I want to write this code without using namespace std;
because I recently learned "polluting the global namespace" is bad practice.
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std; // bad practice, trying to remove
int main() {
std::ofstream outFile; // instead use explicit namespaces
/* lots of code */
// eventually I set some manipulators
outFile << std::fixed << std::showpoint << std::setprecision(2);
/* more code */
// later I wish to unset fixed
outFile.unsetf(ios::fixed); // <-- this part
I was doing fine without the namespace until this outFile.unsetf(ios::fixed)
which works only if I use the namespace std. I have attempted to write the following variations without using the namespace:
outFile.unsetf(ios::fixed)
outFile.unsetf(std::fixed)
outFile.unsetf(ios::std::fixed)
Is ios
a namespace inside of the std
namespace? Then, this next one makes the most sense to me but also does not work.
outFile.unsetf(std::ios::fixed)
Primarily, I would like some help fixing this line using explicit namespaces. Secondarily, if there's a critical knowledge gap I need to close, some help identifying it and maybe some keywords to go look up would be helpful.
Use std::ios_base::fixed
:
outFile.unsetf(std::ios_base::fixed);