C++ 操纵器,C++;我应该按什么顺序使用它们?

C++ 操纵器,C++;我应该按什么顺序使用它们?,c++,manipulators,C++,Manipulators,我正在努力学习操纵者…他们有具体的顺序吗 例如,std::setw在std::setfill之后还是之前,它们应该在单独的行中吗?没有特定的顺序,只需确保包含库即可 关于setw/setfil问题的示例: #include <iostream> #include <iomanip> using namespace std; int main() { cout << setw(10) << setfill('*'); cout &

我正在努力学习操纵者…他们有具体的顺序吗


例如,
std::setw
std::setfill
之后还是之前,它们应该在单独的行中吗?

没有特定的顺序,只需确保包含
库即可

关于setw/setfil问题的示例:

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    cout  << setw(10) << setfill('*');
    cout << 123;
}
#包括
#包括
使用名称空间std;
int main()
{

cout没有具体的顺序。但是请注意,例如,如果您想使用std::left和std::right,或者将所有内容都写在一行中,那么事情可能会变得有点棘手

例如,这不会打印预期输出(仅打印:
7
):


std::请提供格式良好的示例/sscce。
std::cout << std::setw(10) << std::setfill('x') << std::right << 7 << std::endl;
std::cout << std::right << std::setw(10) << std::setfill('x') << 7 << std::endl;
std::cout << std::setfill('x') << std::right << std::setw(10) << 7 << std::endl;
#include <iostream>
#include <iomanip>

int main()
{
    std::cout << std::setw(15) << std::setfill('-') << "PRODUCT" << std::setw(15) << std::setfill('-') << "AMOUNT" << std::endl;
    std::cout << std::setw(15) << std::setfill('-') << "Brush"  << std::setw(15) << std::setfill('-') << 10 << std::endl;
    std::cout << std::setw(15) << std::setfill('-') << "Paste"  << std::setw(15) << std::setfill('-') << 8 << std::endl << std::endl;

    std::cout << std::setw(15) << std::left << std::setfill('-') << "PRODUCT" << std::setw(15) << std::left << std::setfill('-') << "AMOUNT" << std::endl;
    std::cout << std::setw(15) << std::left << std::setfill('-') << "Brush"  << std::setw(15) << std::left << std::setfill('-') << 10 << std::endl;
    std::cout << std::setw(15) << std::left << std::setfill('-') << "Paste"  << std::setw(15) << std::left << std::setfill('-') << 8 << std::endl << std::endl;

    std::cout << std::setw(15) << std::right << std::setfill('-') << "PRODUCT" << std::setw(15) << std::right << std::setfill('-') << "AMOUNT" << std::endl;
    std::cout << std::setw(15) << std::right << std::setfill('-') << "Brush"  << std::setw(15) << std::right << std::setfill('-') << 10 << std::endl;
    std::cout << std::setw(15) << std::right << std::setfill('-') << "Paste"  << std::setw(15) << std::right << std::setfill('-') << 8 << std::endl << std::endl;

    return 0;
}