C ++使用TABS间距

时间:2011-02-26 03:55:38

标签: c++ codeblocks

我正在努力使cout<<intRate<<"\t\t";语句以不同的位置开始,然后cout <<"\t\t"<<monPayment;。我的问题是调整费率和付款值。

我得到的输出结果:

Principal            Interest Rate


   0.07    0.075   0.08    0.085   0.09    0.095   0.1
_______________________________________________________________
100000  665.302 699.215 733.765 768.913 804.623 840.854 877.572
________________________________________________________________
Interest rate is greater than .10 and the value is.105

我试图让它看起来像这样:

Principal               Interest Rate


           0.07    0.075   0.08    0.085   0.09    0.095   0.1
_______________________________________________________________
100000  665.302 699.215 733.765 768.913 804.623 840.854 877.572
________________________________________________________________

Interest rate is greater than .10 and the value is .105

其中0.07与665.302对齐

1 个答案:

答案 0 :(得分:4)

很难从你的问题中看出来,但听起来你正在寻找iomanip

#include <iostream>
#include <iomanip>

int main()
{
    std::cout << setw(4) << 1 << setw(4) << 2 << std::endl;
}

输出:

1   2