gpt4 book ai didi

is there a way to std::basic_istream::get with a basic_streambuf to also read the delimeter char?(有没有办法通过一个BASIC_Streambuf访问std::Basic_iStream::Get,从而也读取定界符字符?)

转载 作者:bug小助手 更新时间:2023-10-25 19:41:36 24 4
gpt4 key购买 nike



Given

vt.给出


#include<string>
#include<stringstream>
#include <fstream>

int main(int argc, char* args[])
{
std::fstream file("MyFile.txt", std::fstream::in);
std::stringbuf sb;
file.get(sb, '\0');
file.get(); // (1) wasting the delimiter char

return 0;
}


Basically, What I am looking for is to avoid doing the (1) statement as it looks just not tidy.

基本上,我正在寻找的是避免做(1)语句,因为它看起来不整洁。


The (approximate) alternative workaround could be getline, but is not dynamically allocated like stringbuf as it requires a fixed size buffer, so it is not an equivalent solution in the case when using a std::basic_streambuf.

另一种(近似的)解决方法是getline,但它不像stringbuf那样动态分配,因为它需要一个固定大小的缓冲区,所以在使用std::basic_streambuf的情况下,它不是一个等效的解决方案。


is there a way with std::basic_istream::get(basic_streambuf&, ...) to also read the delimiter char without forcing to the next statement to do a wasted .get?

有没有办法使用std::Basic_iStream::Get(BASIC_Streambuf&,...)为了在不强制下一条语句执行浪费的.get的情况下读取分隔符字符?


更多回答

en.cppreference.com/w/cpp/string/basic_string/getline

En.cppreference.com/w/cpp/string/basic_string/getline

@n.m.couldbeanAIi am pointing out of getline already in the question, but doesn't fit the use case.

@n.m.couldbeanAII已经在问题中指出了getline,但不符合用例。

eventually there is a seekg(1, fstream::cur) rather than do a wasted get.

最终会有一个sekg(1,fstream::cur),而不是做一个浪费的get。

There are two different functions named getline. "not dynamically allocated like stringbuf as it requires a fixed size buffer" is about one of them.

有两个不同的名为getline的函数。“不像字符串一样动态分配,因为它需要固定大小的缓冲区”就是其中之一。

thanks. i missed that. much appreciated.

谢谢。我很怀念那个。非常感谢。

优秀答案推荐
更多回答

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com