Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. In my console application, printing chinese characters using std::cout(printf), is messy.
Forum Update on Monday, May 27th 2025

In my console application, printing chinese characters using std::cout(printf), is messy.

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 904 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    changtj
    wrote on last edited by changtj
    #1
    //your code here
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        QString qOut = QStringLiteral("输入操作\r\n");
        std::cout << qOut.toStdString().c_str();
    
       char input[256];
    
      std::cin >> input;
    
        return a.exec();
    }
    
    
    jsulmJ 1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      try using std::cout << qPrintable(qOut); or qDebug() << qOut;

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      C 1 Reply Last reply
      5
      • C changtj
        //your code here
        int main(int argc, char *argv[])
        {
            QCoreApplication a(argc, argv);
        
            QString qOut = QStringLiteral("输入操作\r\n");
            std::cout << qOut.toStdString().c_str();
        
           char input[256];
        
          std::cin >> input;
        
            return a.exec();
        }
        
        
        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @changtj Well, c_str() returns a pointer to a C string which only support ASCII. Try without c_str().

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • VRoninV VRonin

          try using std::cout << qPrintable(qOut); or qDebug() << qOut;

          C Offline
          C Offline
          changtj
          wrote on last edited by
          #4

          @VRonin said in In my console application, printing chinese characters using std::cout(printf), is messy.:

          try using std::cout << qPrintable(qOut); or qDebug() << qOut;

          yes, it is ok. thanks very much!

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved