-
0 votesanswersviews
C stringstream,如果word是数字,则除以2
我对编程很新,并且必须创建一个程序来读取提示:“我要花8美元 . ”然后需要在单独的行上打印出每个单词,然后如果任何字符串是数字,则需要将其除以2.因此它应该最终打印为: I have 4 dollars to spend. 我已经设法做了所有事情,除了找到数值并除以2.到目前为止,我有这个: #include <iostream> #include <string&g... -
1 votesanswersviews
C将ifstream用于stringstream
我正在重载我的istream运算符,所以我可以用我的对象替换 std::cin . 我知道我必须为它提供一个空的字符串流,以便最终输出正常工作 . 我想将 std::ifstream 送入 std::stringstream ,如下所示: while(ifs >> ss) {} 这可能吗?这是一个示例原型代码: friend istream & operator >&... -
4 votesanswersviews
istringstream十进制整数输入为8位类型
这个: #include <iostream> #include <sstream> #include <inttypes.h> using namespace std; int main (void) { istringstream iss("123 42"); int8_t x; while (iss >... -
19 votesanswersviews
将数据从fstream复制到stringstream而没有缓冲区?
无论如何我可以将数据从 fstream (一个文件)传输到 stringstream (内存中的流)? 目前,我正在使用缓冲区,但这需要双倍的内存,因为您需要将数据复制到缓冲区,然后将缓冲区复制到字符串流,直到您删除缓冲区,数据在内存中重复 . std::fstream fWrite(fName,std::ios::binary | std::ios::in | std::ios::out); ... -
1 votesanswersviews
将文件读入内存C:是否有std :: strings的getline()
我被要求更新我的代码,该代码读取文本文件并解析它以获取特定的字符串 . 基本上不是每次都打开文本文件,我想将文本文件读入内存并在对象的持续时间内使用它 . 我想知道是否有类似getline()的函数我可以用于std :: string,就像我可以用于std :: ifstream . 我意识到我可以使用while / for循环,但我很好奇是否还有其他方法 . 这是我目前正在做的事情: file.... -
133 votesanswersviews
istringstream,ostringstream和stringstream有什么区别? /为什么不在每种情况下使用stringstream?
我什么时候会使用 std::istringstream , std::ostringstream 和 std::stringstream ?为什么我不应该在每个场景中使用 std::stringstream (是否存在任何运行时性能问题?) . 最后,这有什么不好的(而不是使用流): std::string stHehe("Hello "); stHehe += "... -
1 votesanswersviews
将字符串对象强制转换为istringstream
#include <iostream> #include <fstream> #include <string> #include <vector> #include <algorithm> void reverse_words(const std::string &file) { std::ifstream inFil... -
426 votesanswersviews
你如何清除stringstream变量?
我已经尝试了几件事, std::stringstream m; m.empty(); m.clear(); 两者都不起作用 . -
0 votesanswersviews
在C中使用stringstream和int变量来验证输入是否为int
void get_english_input() { string input = " "; stringstream my_string(input); int ft; double in; while(true) { cout << "Enter an integer value of ...