在C++中解析用引号括起来的东西
Parsing out things surrounded by quotes in C++
我正在尝试制作一个解析器,它只接受用引号括起来的文本,并将其放置在一个新文件中。我已经尝试过很多次了,但都不知道它必须将原始文本从文件中取出,然后将其放置到一个新的文件中。
这就是我目前拥有的:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char current_letter;
char quote_mark = '"';
int isquote = 0;
std::cin >> current_letter;
LOOP : do
{
if(current_letter == quote_mark) {++isquote;}
if(isquote == 1 && current_letter != quote_mark) {std::cout << current_letter;}
if(isquote == 1 && current_letter == quote_mark) {--isquote;}
if(isquote == 0) {goto LOOP;}
} while (cin >> current_letter);
if(cin != current_letter) {cout << "END" <<endl;}
return(0);
它现在不打印任何东西,但它过去只打印随机的东西或只是引号。
您可以这样做:
string str;
getline(cin, str);
string currStr = "";
for (int i = 0; i < str.length(); i++)
{
if (str[i] != '"') currStr += str[i];
}
cout << currStr << "n";
但是,如果要解析的文本中有双引号,这将不起作用
相关文章:
- std::vector的包装器,使数组的结构看起来像结构的数组
- 我可以将一个用clang c++11编译的对象与另一个用c++17编译的对象链接起来吗
- 看起来is_nothrow_constructible_v()在MSVC中被破坏了,我错了吗
- 将大括号括起来的初始值设定项列表作为结构返回
- 学习多线程C++:添加线程不会使执行速度更快,即使它看起来应该
- 将 SDL2 与 CMake 链接起来
- 调用重载的"<大括号括起来的初始值设定项列表>"对于对来说就足够了是模棱两可的
- 如何使用connect将qml按钮与同一类的cpp函数连接起来
- 尽管一切看起来都很好,但值不会交换
- 尝试将 c 字符串数组与分隔符连接起来
- 为什么我会收到此错误?无法将 {lb, ub} 从<大括号括起来的初始值设定项列表>转换为 float(**)(float*, int)
- 有没有办法生成一个包含平方的序列,这些平方加起来就是一个整数平方?
- 计算数组重复次数的组合的有效算法,加起来达到给定的总和
- 自制的上衣:看起来一样,但不完全相同
- 为什么这个复合语句作为用大括号和括号括起来的语句序列似乎不是有效的语句表达式
- 从双引号括起来的子字符串中删除特定字符
- 大括号括起来的初始值设定项列表中的短 c++ 类构造函数
- 嵌套的大括号括起来的初始值设定项列表
- 如何使它看起来像正在下的雪
- 如何在应用程序子项目中将静态库与gradle子项目链接起来