如何在 VC++ 中处理字符串? [英] How to handle strings in VC++?

查看:33
本文介绍了如何在 VC++ 中处理字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦我们接受来自键盘的输入,我们如何在 VC++ 中将该字符添加到字符串中?

Once we accept an input from a keyboard, How can we add that character into a string in VC++?

谁能帮我解决这个问题?

Can anyone help me with this?

推荐答案

您可以使用 STL 中的 std::string 以及 + 或 += 运算符.

You can use std::string from STL, and the + or += operator.

要做到这一点,#include 并使用 std::string 类.

To do this, #include <string> and use the class std::string.

之后,有多种方法可以存储来自用户的输入.

After that, there are various ways to store the input from the user.

首先,您可以将输入的字符直接存储到字符串中:

First, you may store the character input directly into the string:

std::string myStr;
std::cin >> myStr;

其次,您可以将输入附加到现有字符串:

Second, you can append the input to an existing string:

std::string myStr;
myOtherStr += myStr;

这篇关于如何在 VC++ 中处理字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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