user1633272
user1633272

Reputation: 2309

Any c++ string library like QString (or Java String)?

I'm working on a windows program using MFC, currently I use std::string and std::wstring, the problems are I have to convert them from each other and handle encoding everywhere.

The QString API looks very decent, it can handle those problems just in one class, so my questions are:

  1. Can I use only QString without depending on whole QT library?
  2. Is there alternatives (A class handling both char and wchar, encoding, etc.)

Upvotes: 2

Views: 687

Answers (2)

Vlad Feinstein
Vlad Feinstein

Reputation: 11311

MFC has its own implementation of the string class: CString https://learn.microsoft.com/en-us/cpp/atl-mfc-shared/using-cstring?view=vs-2019

Upvotes: 1

Altinsystems
Altinsystems

Reputation: 356

  1. Can I use only QString without depending on whole QT library? Yes you can. You havn't to use other Qt libraries.

  2. QString has a lot useful functions to convert the QString into a other type, like:

    std::wstring wString;
    wString = 'w';
    QString qString = QString::fromStdWString(wString);
    std::string sString = qString.toStdString();
    const char * cP = sString.c_str();
    qString = cP;
    wString = qString.toStdWString();

Upvotes: 2

Related Questions