问题标签 [sstream]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c++ - What is the best way (performance driven) to convert and write variables to a file in c++?
I want to write something like this to a file:
And so on... Its a program instruction trace which will have thousands of lines.
I am reading from an 'elf' decoding the instruction, creating an object, setting its address, instruction, name and registers parameters and then writing it in the above format to a file.
What it is the best way, measuring in speed/performance, to do this?
Now I have this (still just hexadecimals) and I don't know if it is the best way to continue writing my code:
Converting function:
And the writing:
EDIT:
So I have reached a faster solution based on the answers.
For one I implemented the solution given by Escualo to stop creating objects each time I read a new instruction.
And then I read the answer given by Thomas Matthews and gave me the idea to not write to my file at every instruction read, so the stringstream now works like a buffer with size 1024, and when it surpasses that value then writes the stream to the file:
c++ - sstream 不填充向量 C++
在命令行中输入:
存储在“行”中,我的向量仅被填充
我究竟做错了什么?这是代码
c++ - 拆分较大的字符串并在找到特定字符时停止
输入是标准字符串输入。像这样。
“阿南德,拉梅什,苏雷什#阿南德,拉梅什,苏雷什,苏雷什,阿南德”
我想在 # 之前获取所有名称并将其存储在一个数组中。并使用# 后的名称进行一些操作。
如何将 # 之前的前三个名称复制到数组中。到目前为止,我已经弄清楚如何复制用逗号分隔的字符串。在找到特定元素后,我找不到停止的解决方案。遇到 # 时如何停止。到目前为止,这是我的代码:
c++ - 如何使用 ostrstream 避免缓冲区溢出
我有一个代码,我在 vxworks 机器中编译和加载它,我看到缓冲区溢出。
这里的问题是,内存请求在 while 中的每个循环中都会增加一倍。
当分配请求超出最大可用块时,会导致陷阱。
我认为我们看到这种行为是因为重用了 ostrstream 对象。
如何纠正这种行为?
c++ - 遍历字符串时的Stringstream不起作用
所以我想使用字符串流将字符串转换为整数。
假设一切都完成了:
一个似乎有效的基本案例是当我这样做时:
效果很好。
但是,可以说我有一个字符串定义为:
我这样做:
这不像我想要的那样工作。本质上,我要单独处理字符串的每个元素,就好像它是一个数字一样,所以我想先将它转换为 int,但我似乎也不能。有人可以帮我吗?
我得到的错误是:
c++ - c++中stoi关键字使用什么库
我的问题很简单,但我似乎无法找到它。我想知道使用stoi
. 我正在使用atoi
,它适用于
但是当我使用stoi
. 谢谢
c++ - C ++读取文件,忽略逗号并将数据输出到屏幕
我有一个格式为:FirstName,MiddleName,LastName,Major,City,State,GPA 的文件
我正在尝试读取文件并将不带逗号的数据输出到屏幕上。这是我到目前为止所拥有的,但它只输出 GPA:
c++ - 为什么我会超时(使用 sstream 解析以逗号分隔的整数列表)?
我得到一个由逗号分隔的 n 个整数的输入字符串(例如“23,4,56”)。我需要设置一个字符串流来表示这个字符串,然后用它将每个整数扫描成一个向量。向量的元素(列表中的整数)最终将逐行输出。我得到了 main(),并且只负责编写 parseInts(string str)。出于某种原因,我一直在超时。我猜这是我的 while 循环中的一些东西,特别是关于我如何使用 str() 操作我的 sstream,但我无法弄清楚到底发生了什么。我是 sstream 和 C++ 的新手,所以任何帮助都将不胜感激!
c++ - 在交互式程序中使用带有 cout 和 stringstream 的预处理器指令 - C++
所以如果我有一个像这样的简单交互式程序:
我如何使它能够包含我的指令“#define”,以便打印到标准输出的所有行都将在程序末尾由 cout << os.str() 打印,当这样做时它还会将最终的“cout”变成“os”吗?我已经尝试在最后使用 printf 而不是 os,并且遇到了麻烦/编译器错误,说“没有对 printf 的匹配函数调用”。
我希望我的问题是有道理的,如果这个问题已经被问过,但我在这里找不到它,我深表歉意。
c++ - C ++ sstream跳过文件的前三个输入
我需要以这种格式打开一个文件
我需要将行的名字分配给结构的成员数组,将行的姓分配给结构的另一个成员,将行的每个编号分配给结构中的分数数组,并且每个新行都转到下一个结构数组的索引,做同样的事情(对不起,如果我措辞不好)。
我的名字和姓氏分配很顺利,但是当将数字分配给结构成员时,它会跳过前三个数字。我究竟做错了什么?
这是我的代码
这是输出