C ++中不同字符串类型的优缺点 [英] Pros and Cons of different string types in C++

查看:115
本文介绍了C ++中不同字符串类型的优缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉在SO上提出了另一个无法解决的问题,但我只是对C ++中所有不同字符串类型的优缺点感到好奇。我的特定问题是在MFC的CString和std :: string之间(因为我使用的是Windows专用软件),但这将扩展到C ++中的任何字符串格式。到底什么是C ++中使用的最佳字符串类型,为什么?

Sorry to start another of those unanswerable questions on SO, but I'm just curious as to the pros and cons of all the different string types in C++. My particular question is between MFC's CStrings and std::string (since I'm doing Windows only software), but this would extend to any of the string formats in C++. What do you all thing is the best string type to use in C++ and why?

更新:我实际上发现了一个重复的问题。感谢那些已经回答过的人。请针对这个其他问题提出任何新的答案:如何使用C ++处理字符串?

UPDATE: I actually found a duplicate question. Thanks to those who already answered. Please direct any new responses to this other question: How do you handle strings in C++?

推荐答案

在罗马时,就像罗马人一样。如果您使用的是MFC,请使用CString,因为所有类均已针对它进行了优化。除此以外,请使用std :: string,因为这是标准操作,您会发现在其他情况下该体验也很有用。

When in Rome, do as the Romans do. If you're using MFC, use CString because the classes are all optimized for it. Anything else, use std::string, because it's the standard and you'll find the experience useful in other contexts.

这篇关于C ++中不同字符串类型的优缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆