在 C++ 98 中输入双引号

Input double quotes in C++ 98

本文关键字:输入 C++      更新时间:2023-10-16

我已经经历了其他StackOverflow问题,但我需要的几乎没有什么不同。我有一个长字符串(可能来自某个 Word 文档),我想计算字符串的字符数。我正在string s3=<paste the string here>如何继续的代码中复制该长字符串。我不需要 C++11 中的解决方案。

#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s1="My test"; //Works
    string s2="My" "test"; //Still works
    string s3="My"1003"test"; //Doest work. My string being input from user is `My "1003" test`. If i input it in string it becomes "My "1003" test.
    cout<<s;
}

编辑:首先阅读问题并尝试了解这里的捕获点是什么,而不是盲目地建议重复。转义字符并不方便,因为字符串可能包含大量双引号,并且手动使用转义字符作为双引号并不方便。

如果要

在源代码中输入包含"的字符串,则需要将其转义为"

示例:"My"1003"test" 是包含字母"M"、字母"y"、引号、数字 1 等的字符串。