使用固定空格打印

发布于 2024-08-25 15:17:09 字数 81 浏览 6 评论 0原文

我想打印两个字符串(例如“ABC”和“DEF”),在“ABC”之前有 5 个空格字符,并且第二个字符串将在第一个字符串开头之后的 7 个字符处开始。

I want to print two strings (say "ABC" and "DEF") with 5 space characters before "ABC" and that the second string will start 7 characters after the beginning of the first string.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感受沵的脚步 2024-09-01 15:17:09

我怀疑您正在寻找 width() 方法:

#include <iostream>
#include <string>
using namespace std;

int main()
{
  string abc = "ABC";
  string edf = "EDF";
  cout.width(8);
  cout << abc;
  cout.width(7);
  cout << edf;
  return 0;
}

I suspect you're looking for the width() method:

#include <iostream>
#include <string>
using namespace std;

int main()
{
  string abc = "ABC";
  string edf = "EDF";
  cout.width(8);
  cout << abc;
  cout.width(7);
  cout << edf;
  return 0;
}
遥远的绿洲 2024-09-01 15:17:09
#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

int main() 
{ 
char a[] = "ABC";
char b[] = "EDF";
cout<"     "<<a<<"       "<<b;
return 0; 
}
#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

int main() 
{ 
char a[] = "ABC";
char b[] = "EDF";
cout<"     "<<a<<"       "<<b;
return 0; 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文