简体   繁体   English

使用 setw(20) 无法显示正确的 output

[英]Cannot display the correct output using setw(20)

Here is my code.这是我的代码。 I tried all the different ways with left << setw(20) but it does not show me the proper outcome.我用 left << setw(20)尝试了所有不同的方法,但它没有向我显示正确的结果。

void MotorVehicle::moveTo(const char* address)
    {
        if (strcmp(Address, address) != 0)
        {
            cout << "|" << setw(10) << PlateNumber << "| |" << setw(20) << Address << " --->--- ";
            cout << address << "|" << endl;
            strcpy(Address, address);
        }
    }

Hi guys this is the expected out put.大家好,这是预期的输出。

|    T-1111| |            Montreal --->--- New York            |
|    T-1111| |            New York --->--- New Jersey          |
|    T-1111| |            New Jersey --->--- Toronto           |

Remember setw is not 'sticky'.请记住setw不是“粘性”。 It only applies to the subsequent output field.仅适用于后续的 output 字段。 All other manipulators apply until the are superseded.在被取代之前,所有其他操纵器均适用。

Thus I think you want:因此,我认为您想要:

 cout << setw(20) << left << address << "|" << endl;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM