帮助使代码正常运行 [英] Help Make the code proper functional
本文介绍了帮助使代码正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我遇到问题
i有以下代码
Hi All,
I am facing a problem
i have the following code
#include <iostream>
#include <sstream>
#include <vector>
#include <iomanip>
using namespace std;
int main(){
string key = "30 14 06 03 55 04 03 14 0D 2A";
istringstream iss(key);
vector<char> data;
unsigned x;
iss >> hex;
while(iss >> x){
data.push_back(x);
}
size_t size = data.size();
cout << "char data[" << size << "];" << endl;
for(int i=0;i < size ; ++i){
cout << "data[" << i << "] = 0x"
<< hex << uppercase << setw(2) << setfill('0') << (unsigned)data[i] << ';' << endl;
}
}
i希望输出像这样
i want the output to be like this
content[0] = 0x30;
content[1] = 0x14;
content[2] = 0x06;
content[3] = 0x03;
content[4] = 0x55;
content[5] = 0x04;
content[6] = 0x03;
content[7] = 0x14;
content[8] = 0x0D;
content[9] = 0x2A;
所以我在for循环中做了更改
so i made changes in the for loop
unsigned *content;
content = (unsigned) malloc(size);
for(int i=0;i < size ; ++i){
cout << "data[" << i << "] = 0x"
<< hex << uppercase << setw(2) << setfill('0') << (unsigned)data[i] << ';' << endl;
cout<<"a is" <<a<<endl;
content[i]=data[i];
cout<<"content[i] is" <<content[i]<<endl;
然后我意识到我已经在cout中完成了0x打印,请帮助我实现fainl输出
Then i realized i have done the 0x printing in cout only please help me in achieving the fainl output
推荐答案
您只需要为每一行添加额外的endl
,例如:
You just need to add an extraendl
to each line, like:
for(int i=0;i < size ; ++i)
{
cout << "content[" << i << "] = 0x" << hex << uppercase << setw(2) << setfill('0') << (unsigned)data[i] << ';' << endl << endl;
}
[edit]
添加了额外的终结。
[/ edit]
[edit]
Added the extra endline.
[/edit]
这篇关于帮助使代码正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文