c++根据用户定义的列数输出到控制台的格式
我喜欢根据用户的模板或ini文件将数据信息显示到dos控制台。 例子, UserTemplate.txt
ParamA=yes
ParamB=yes
ParamC=yes
ParamD=yes
ParamE=yes
ParamF=no
ParamG=yes
ParamH=no
..
..
我的程序将读取这个UserTemplate.txt以及用户想要显示到dos控制台的参数。
while (!file_opc.eof())
{
std::vector<std::string> v;
file_opc.getline(str,200);
cout <<"\nline"<<str<<endl;
if (strstr(str, "=") != NULL)
{
boost::algorithm::split_regex( v, str, boost::regex( "=|//" ) ) ;
cout<<"Param="<<v.at(0)<<"\nFlag="<< v.at(1)<<endl;
ParamNames.push_back(v.at(0).c_str());
ParamFlags.push_back(v.at(1).c_str());
}
}
列数的输出格式是来自用户的基于变量的标志(是/否),
ParamA ParamB ParamC ParamD ParamE ParamG
------ ------ ------ ------ ------ ------
123 Ack NewTx 24.0 Block 64QAM
因为 ParamF 和 ParamH 设置为“否”。它不会显示到 dos 控制台。 那些“123”、“Ack”、“NewTx”等是从数据源解析的向量。我需要帮助如何根据 UserTemplate.txt 将这些 ParamX 转储到 dos 控制台
现在,我对一些参数进行了硬编码,如下所示。
//////////////////
cout<<"cRnti trNum ackNack harqNum RachM2 ReliTransF MCS CW1 SINRPUSCH "<<endl;
cout<<"===== ===== ======= ======= ====== ========== ======= ========= "<<endl;
SetConsoleTextAttribute(hhConsole, 15);
for (unsigned int i=0;i<RecordInMemory;i++)
{
ss<<setw(5)<<cRnti[i]<<setw(8)<<trNumCw1[i]<<setw(8)<<ackNackDtxCw1[i]<<setw(9)<<harqNumCw1[i]<<setw(10)<<pdcchOrRachM2[i]<<setw(10)<<reliableTransmissionFlag[i]<<setw(12)<<mcsIndexCw1[i]<<setw(12)<<sinrPusch[i];
cout<<ss.str()<<endl;
ss.str(std::string());
}
如果您有更好的主意来处理我的案子,请粉碎光线,我很感激。它为我节省了很多时间。如果您知道该网站已经有解决方案,请给我一个链接。提前致谢。
I like to display data information to dos console based on user's template or ini file.
Example,
UserTemplate.txt
ParamA=yes
ParamB=yes
ParamC=yes
ParamD=yes
ParamE=yes
ParamF=no
ParamG=yes
ParamH=no
..
..
My program will read this UserTemplate.txt and what parameter user wants to display to dos console.
while (!file_opc.eof())
{
std::vector<std::string> v;
file_opc.getline(str,200);
cout <<"\nline"<<str<<endl;
if (strstr(str, "=") != NULL)
{
boost::algorithm::split_regex( v, str, boost::regex( "=|//" ) ) ;
cout<<"Param="<<v.at(0)<<"\nFlag="<< v.at(1)<<endl;
ParamNames.push_back(v.at(0).c_str());
ParamFlags.push_back(v.at(1).c_str());
}
}
Output format for number of Columns are variable based flags (yes/no) from user
ParamA ParamB ParamC ParamD ParamE ParamG
------ ------ ------ ------ ------ ------
123 Ack NewTx 24.0 Block 64QAM
Since ParamF and ParamH sets no NO. It won't display to dos console.
Those "123", "Ack", "NewTx" etc.. are the vectors parsed from a data source. I need help how dump those ParamX to dos console based on UserTemplate.txt
Right now, I am hard-coded some parameters as follow.
//////////////////
cout<<"cRnti trNum ackNack harqNum RachM2 ReliTransF MCS CW1 SINRPUSCH "<<endl;
cout<<"===== ===== ======= ======= ====== ========== ======= ========= "<<endl;
SetConsoleTextAttribute(hhConsole, 15);
for (unsigned int i=0;i<RecordInMemory;i++)
{
ss<<setw(5)<<cRnti[i]<<setw(8)<<trNumCw1[i]<<setw(8)<<ackNackDtxCw1[i]<<setw(9)<<harqNumCw1[i]<<setw(10)<<pdcchOrRachM2[i]<<setw(10)<<reliableTransmissionFlag[i]<<setw(12)<<mcsIndexCw1[i]<<setw(12)<<sinrPusch[i];
cout<<ss.str()<<endl;
ss.str(std::string());
}
If you have better idea to handle my case, please shred the light, I appreciate. It saves me a lot of times. If you know there is already solution in this site, please give me a link. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可能会创建一个小型数据结构,告诉如何(以及是否)显示每一列:
然后我们添加一些代码来读取文件中的每个名称:显示对:
然后您将列的数据读入这些结构(并且可能以某种方式添加正确的宽度,无论是内部存储还是来自另一个外部源):
最后,您将使用指定的参数写出数据:
至少目前,这假设您的“记录”类型是还有一个映射(或该顺序上的某些内容),可让您根据从 userTemplate.txt 文件中读取的相同列名查找数据。
I would probably create a small data structure that tells how (and if) to display each column:
Then we'd add some code to read each name:display pair from the file:
Then you'd read your data for the columns into these structures (and presumably add the correct widths somehow or other, either stored internally or from another external source):
Finally, you'd write out the data using the specified parameters:
At least for the moment, this assumes your "record" type is also a map (or something on that order) that lets you look up the data based on the same column name that's read from the userTemplate.txt file.