【问题标题】:How to print a String in a C++ Builder console application?如何在 C++ Builder 控制台应用程序中打印字符串?
【发布时间】:2023-01-03 23:07:17
【问题描述】:

祝大家新年快乐。我正在尝试在控制台应用程序中打印 String 的内容。我正在做一个测试,想可视化内容以进行调试。

这是我的代码:

bool Tests::test001() {
    std::string temp;

    CDecoder decoder;  // Create an instance of the CDecoder class
    String input = "60000000190210703800000EC00000164593560001791662000000000000080000000002104302040235313531353135313531353153414C4535313030313233343536373831323334353637383930313233";
    String expected_output = "6000000019";
    String output = decoder.getTPDU(input);  // Call the getTPDU method
    std::cout << "Expected :" << expected_output.t_str() <<std::endl;
    std::cout << "Obtained :" << output.t_str() <<std::endl;
    
    return output == expected_output;  // Return true if the output is as expected, false otherwise
}

这就是我得到的:

运行测试:0 预期:024B8874 获得:00527226 测试失败 按任意键继续...

这就是我想要得到的:

运行测试:0 预计:6000000019 获得:0000001902 测试失败 按任意键继续...

这里获得的值是我随机选择的输入的子字符串(向左移动两个字符)。

无论我使用 t_str() 还是 c_str(),结果都是一样的。

任何提示将不胜感激。

【问题讨论】:

    标签: c++builder


    【解决方案1】:

    这似乎可以完成工作:

    std::wcout

    这是工作代码:

    // Member function to run test001
    bool Tests::test001() {
        std::string temp;
    
        CDecoder decoder;  // Create an instance of the CDecoder class
        String input = "60000000190210703800000EC00000164593560001791662000000000000080000000002104302040235313531353135313531353153414C4535313030313233343536373831323334353637383930313233";
        String expected_output = "6000000019";
        String output = decoder.getTPDU(input);  // Call the getTPDU method
        std::wcout << "Expected: " << expected_output.c_str() <<std::endl;
        std::wcout << "Obtained: " << output.c_str() <<std::endl;
    
        return output == expected_output;  // Return true if the output is as expected, false otherwise
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多