如何从boost :: asio :: streambuf获取二进制数据(How to get binary data from boost::asio::streambuf)
如何将数据从streambuf刷新到文件? 我试过了
read(*socket_, streamBuf, boost::asio::transfer_at_least(694784)) std::istream is(&streamBuf); std::ofstream outfile; outfile.open ("test.exe"); is >> outfile; outfile.close()
但那没用。 有任何线索如何做到这一点?
How can I flush data from streambuf to file? I've tried
read(*socket_, streamBuf, boost::asio::transfer_at_least(694784)) std::istream is(&streamBuf); std::ofstream outfile; outfile.open ("test.exe"); is >> outfile; outfile.close()
but that didn't work. Any clue how to do that?
原文:https://stackoverflow.com/questions/4896609
更新时间:2023-04-10 21:04
最满意答案
您可以将字符串切片N次,为每个字符串指定N的步长:
>>> s = "Hello I am the input string" >>> columns = 5 >>> seq = [s[i::columns] for i in range(columns)] >>> print seq ['H i n', 'eItnsg', 'l hpt', 'laeur', 'om ti'] >>> print "\n".join(seq) H i n eItnsg l hpt laeur om ti
You could slice the string N times, specifying a step of N for each one:
>>> s = "Hello I am the input string" >>> columns = 5 >>> seq = [s[i::columns] for i in range(columns)] >>> print seq ['H i n', 'eItnsg', 'l hpt', 'laeur', 'om ti'] >>> print "\n".join(seq) H i n eItnsg l hpt laeur om ti
相关问答
更多-
使用String.repeat "x".repeat(10); https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/repeat 在旧浏览器上你可以做到 new Array(10).join('x') use String.repeat "x".repeat(10); https://developer.mozilla.org/en/docs/Web/JavaScript/Refere ...
-
Python:获取列表中第一个字符串的第一个字符?(Python: Get the first character of the first string in a list?)[2021-02-01]
你差不多了 最简单的方法是 mylist[0][0] # get the first character from the first item in the list 但 mylist[0][:1] # get up to the first character in the first item in the list 也会工作。 你想要在第一个字符(字符零)之后结束,不是在第一个字符(字符零)之后开始 ,这是你的问题的代码意味着什么。 You almost had it right. The ... -
有效地检查该字符串由Python中的一个字符组成(efficiently checking that string consists of one character in Python)[2023-11-19]
这是迄今为止最快的,甚至比count()快几倍,只是时间与那个优秀的mgilson的时间套件 : s == len(s) * s[0] 这里所有的检查都是在Python C代码中完成的: 分配len(s)个字符; 用第一个字符填充空格; 比较两个字符串。 字符串越长,时间奖金越大。 但是,如mgilson所写,它创建一个字符串的副本,所以如果你的字符串长度是数百万个符号,它可能会成为一个问题。 从时序结果可以看出,一般来说,解决任务的最快方法不会为每个符号执行任何Python代码。 然而, set()解决 ... -
public int GetNthIndex(string s, char t, int n) { int count = 0; for (int i = 0; i < s.Length; i++) { if (s[i] == t) { count++; if (count == n) { return i; } ...
-
s = ":dfa:sif:e" print s[1:] 版画 dfa:sif:e python 2.x s = ":dfa:sif:e" print s[1:] python 3.x s = ":dfa:sif:e" print(s[1:]) both prints dfa:sif:e
-
不要修改字符串。 与他们一起工作; 只有在需要时才将它们变成字符串。 >>> s = list("Hello zorld") >>> s ['H', 'e', 'l', 'l', 'o', ' ', 'z', 'o', 'r', 'l', 'd'] >>> s[6] = 'W' >>> s ['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd'] >>> "".join(s) 'Hello World' Python字符串是不可变的(即它们不能被修改) ...
-
在Python中,字符串是不可变的,所以你必须创建一个新的字符串。 您有几个如何创建新字符串的选项。 如果你想删除'M'出现在哪里: newstr = oldstr.replace("M", "") 如果要删除中心字符: midlen = len(oldstr)/2 newstr = oldstr[:midlen] + oldstr[midlen+1:] 您询问字符串是否以特殊字符结尾。 不,你想像一个C程序员。 在Python中,字符串以其长度存储,因此任何字节值(包括\0 )都可以出现在字符串中。 ...
-
在Python中创建一个包含另一个字符串的第n个字符的字符串(Create a string with every nth character of another string in Python)[2024-01-17]
您可以将字符串切片N次,为每个字符串指定N的步长: >>> s = "Hello I am the input string" >>> columns = 5 >>> seq = [s[i::columns] for i in range(columns)] >>> print seq ['H i n', 'eItnsg', 'l hpt', 'laeur', 'om ti'] >>> print "\n".join(seq) H i n eItnsg l hpt laeur om ti You co ... -
x = zip(*[iter(my_array)]*5) 这是一个很酷但难以阅读的方式 通常它是通过列表理解来完成的 n = 5 x = [my_array[i:i+n] for i in range(0,len(my_array),n)] 这篇文章解释了最好的答案http://www.stavros.io/posts/brilliant-or-insane-code/ x = zip(*[iter(my_array)]*5) is a cool but hard to read way of do ...
-
你的问题在这里: n+=n; 第一次是2,然后是4,然后是8 ...... 只需使用单独的柜台。 Your problem here: n+=n; first time it 2, then 4, then 8... Just use separate counter.