Javascript 将ostream分配给c++;
我有一个下面的方法,我可以通过名称来理解,就是将输出转换为一个漂亮的格式来显示。但我不明白这段代码在做什么,它的返回类型是什么。如何将此返回类型分配给要从Javascript 将ostream分配给c++;,javascript,c++,visual-studio,Javascript,C++,Visual Studio,我有一个下面的方法,我可以通过名称来理解,就是将输出转换为一个漂亮的格式来显示。但我不明白这段代码在做什么,它的返回类型是什么。如何将此返回类型分配给要从javascript std::ostream & prettyPrintRaw(std::ostream &out, const std::vector<unsigned char> &buf) { vector<unsigned char>::const_iterator ptr = buf
javascript
std::ostream & prettyPrintRaw(std::ostream &out, const std::vector<unsigned char> &buf) {
vector<unsigned char>::const_iterator ptr = buf.begin();
vector<unsigned char>::const_iterator end = buf.end();
int i = 0;
while (ptr != end) {
char c = (char) *ptr;
if (c >= ' ' && c <= '~') {
out.put(c);
barCodeDataChar[i] = c;
i++;
}
else
out << '{' << (int) c << '}';
ptr++;
} // end while
return out;
} // end function
std::ostream&prettyPrintRaw(std::ostream&out,const std::vector&buf){
vector::const_迭代器ptr=buf.begin();
vector::const_迭代器end=buf.end();
int i=0;
while(ptr!=结束){
字符c=(字符)*ptr;
如果(c>=''&&c您可以删除std::ostream&out
参数,并使用字符串流构造字符串值
然后可以使用myStringStream.str()
获取字符串
#include <sstream>
#include <string>
std::string prettyPrintRaw(const std::vector<char> &buf) {
auto ptr = buf.begin();
auto end = buf.end();
std::stringstream out;
int i = 0;
while (ptr != end) {
char c = (char) *ptr;
if (c >= ' ' && c <= '~'){
out.put(c);
i++;
}
else {
out << '{' << (int) c << '}';
}
ptr++;
}
return out.str();
}
#包括
#包括
std::string prettyPrintRaw(const std::vector和buf){
自动ptr=buf.begin();
自动结束=buf.end();
std::stringout;
int i=0;
while(ptr!=结束){
字符c=(字符)*ptr;
如果(c>=''&&c谢谢Kanjio,但我必须做以下更改才能使其正常工作
std::string prettyPrintRaw1(const std::vector<unsigned char> &buf) {
vector<unsigned char>::const_iterator ptr = buf.begin();
vector<unsigned char>::const_iterator end = buf.end();
std::stringstream out;
int i = 0;
while (ptr != end) {
char c = (char) *ptr;
if (c >= ' ' && c <= '~'){
out.put(c);
}
else {
out << '{' << (int) c << '}';
}
ptr++;
}
return out.str();
std::string prettyPrintRaw1(const std::vector&buf){
vector::const_迭代器ptr=buf.begin();
vector::const_迭代器end=buf.end();
std::stringout;
int i=0;
while(ptr!=结束){
字符c=(字符)*ptr;
如果(c>=''&&c可能是其拼写的汉字而不是汉字的副本,或者也可能是其拼写的汉字)