What is the correct type of std :: fixed, std :: scientific, etc. In c ++?

I'm trying to fit std::fixed, std::scientificetc. into a variable, but I can’t figure out how to do it. I am trying to use this code, but it does not work:

typedef std::vector<std::ios_base> FlagArray;

int main() {
    FlagArray tmp1 = { std::fixed, std::scientific };
    FlagArray tmp2 = { std::internal, std::right, std::left };
    FlagArray tmp3 = { std::uppercase, std::showbase, std::showpoint, std::showpos };
    return 0;
}
+4
source share
1 answer

Type of these manipulators std::ios_base &(std::ios_base &str). These are the functions.

That means what you need to use std::vector<std::ios_base &(*)(std::ios_base &str)> FlagArray;.


Here is what your code looks like:

#include <iostream>
#include <vector>
#include <ios>

typedef std::vector<std::ios_base &(*)(std::ios_base &str)> FlagArray;

int main() {
    FlagArray tmp1 = {std::fixed,std::scientific};
    FlagArray tmp2 = {std::internal,std::right,std::left};
    FlagArray tmp3 = {std::uppercase,std::showbase,std::showpoint,std::showpos};
    return 0;
}
+6
source

Source: https://habr.com/ru/post/1616939/


All Articles