求助

grellen 2008-03-25 03:54:30

如何使下面输出的整数输出时能够对齐啊

#include <iostream>
#include<ctime>
#include <vector>
#include <algorithm>
#include<iomanip>
using namespace std;
class S
{
vector<int> a;
public:
int b;
S();
void beforesort(S c);
void sort(S c);
};
S::S()
{

srand((unsigned)time(NULL));

for(int i = 0; i < 100; i++ )
{
b = rand ( )%1000;
a.push_back(b);
}
}
void S::beforesort(S c)
{
cout<< "排列前:\n";
for( int i = 0; i < 100; i++ )
{
cout<< c.a[i]<<" ";
if ( ( i + 1 ) % 10 == 0 )
cout<<endl;
}
}
void S::sort(S c)
{
cout<< "排列后:\n";
std::sort(c.a.begin(), c.a.end());
for( int i = 0; i < 100; i++ )
{
cout<< c.a[i]<<" ";
if ( ( i + 1 ) % 10 == 0 )
cout << endl;
}
}
void main()
{
S a;
a.beforesort(a);
a.sort (a);
}
...全文
87 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
great3779 2008-03-26
  • 打赏
  • 举报
回复

if (bCutPlane)
{
pTOC->nCounter++;
pTOC->dCoord = dCoor;
strcpy(pTOC->szBlock, "BLOCK: GetPath");
strcpy(pTOC->szReason, "REASON: Path cut plane");
fprintf(pTOC->pFile, "[%d]\n", pTOC->nCounter);
fprintf(pTOC->pFile, "Coordinate: %f\n");
fprintf(pTOC->pFile, "%s\n", pTOC->szBlock);
fprintf(pTOC->pFile, "%s\n\n", pTOC->szReason);
return PATH_CUT_PLANE;
}
great3779 2008-03-26
  • 打赏
  • 举报
回复

if (bCutPlane)
{
pTOC->nCounter++;
pTOC->dCoord = dCoor;
strcpy(pTOC->szBlock, "BLOCK: GetPath");
strcpy(pTOC->szReason, "REASON: Path cut plane");
fprintf(pTOC->pFile, "[%d]\n", pTOC->nCounter);
fprintf(pTOC->pFile, "Coordinate: %f\n");
fprintf(pTOC->pFile, "%s\n", pTOC->szBlock);
fprintf(pTOC->pFile, "%s\n\n", pTOC->szReason);
return PATH_CUT_PLANE;
}
great3779 2008-03-26
  • 打赏
  • 举报
回复
做个实验。。。

if (bCutPlane)
{
pTOC->nCounter++;
pTOC->dCoord = dCoor;
strcpy(pTOC->szBlock, "BLOCK: GetPath");
strcpy(pTOC->szReason, "REASON: Path cut plane");
fprintf(pTOC->pFile, "[%d]\n", pTOC->nCounter);
fprintf(pTOC->pFile, "Coordinate: %f\n");
fprintf(pTOC->pFile, "%s\n", pTOC->szBlock);
fprintf(pTOC->pFile, "%s\n\n", pTOC->szReason);
return PATH_CUT_PLANE;
}
great3779 2008-03-26
  • 打赏
  • 举报
回复
非常感谢coding兄的回答!
野男孩 2008-03-25
  • 打赏
  • 举报
回复
发帖的地方上面有一排图标,看见没?

第二个是B,第7个就是格式化代码。
great3779 2008-03-25
  • 打赏
  • 举报
回复
各位,代码模板怎么用啊?如何能像你们一样,发整齐的代码?
Kowenxi 2008-03-25
  • 打赏
  • 举报
回复
up
TeddyGe 2008-03-25
  • 打赏
  • 举报
回复
修改后的程序


#include <iostream>
#include<ctime>
#include <vector>
#include <algorithm>
#include<iomanip>
using namespace std;
class S
{
vector<int> a;
public:
int b;
S();
void beforesort(S c);
void sort(S c);
};
S::S()
{

srand((unsigned)time(NULL));

for(int i = 0; i < 100; i++ )
{
b = rand ( )%1000;


a.push_back(b);
}
}
void S::beforesort(S c)
{
cout<< "排列前:\n";
for( int i = 0; i < 100; i++ )
{
cout<< c.a[i]<<"\t";
if ( ( i + 1 ) % 10 == 0 )
cout<<endl;
}
}
void S::sort(S c)
{
cout<< "排列后:\n";
std::sort(c.a.begin(), c.a.end());
for( int i = 0; i < 100; i++ )
{
cout<< c.a[i]<<"\t";
if ( ( i + 1 ) % 10 == 0 )
cout << endl;
}
}
void main()
{
S a;
a.beforesort(a);
a.sort (a);

cin.get() ;
}
ttkk_2007 2008-03-25
  • 打赏
  • 举报
回复

#include <iostream>
#include<ctime>
#include <vector>
#include <algorithm>
#include<iomanip>
using namespace std;

class S
{
vector<int> a;
public:
int b;
S();
void beforesort(S c);
void sort(S c);
};
S::S()
{

srand((unsigned)time(NULL));

for(int i = 0; i < 100; i++ )
{
b = rand ( )%1000;
a.push_back(b);
}
}
void S::beforesort(S c)
{
cout<< "排列前:\n";
for( int i = 0; i < 100; i++ )
{
cout<< setw(6) << c.a[i];
if ( ( i + 1 ) % 10 == 0 )
cout<<endl;
}
}
void S::sort(S c)
{
cout<< "排列后:\n";
std::sort(c.a.begin(), c.a.end());
for( int i = 0; i < 100; i++ )
{
cout<< setw(6) << c.a[i];
if ( ( i + 1 ) % 10 == 0 )
cout << endl;
}
}
void main()
{
S a;
a.beforesort(a);
a.sort (a);
}

Supper_Jerry 2008-03-25
  • 打赏
  • 举报
回复
cout<<setw(6) << c.a[i];

64,651

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧