【问题标题】:How can I get this output in C++ visual studio? [closed]如何在 C++ Visual Studio 中获得此输出? [关闭]
【发布时间】:2020-01-24 03:18:44
【问题描述】:
#include <iostream>
using namespace std;
int main()
{
    cout << "Hi. My name is blank. " << endl;
    cout << "my hobby is";
    cout << "my pet's name is" << endl; 
    return 0;
}

我明白了:

嗨。我的名字是空白的。我的爱好是。我的宠物的名字是。

我需要它看起来像三行:

嗨。我的名字是空白的。
我的爱好是。
我的宠物名字是。

【问题讨论】:

  • 我需要“嗨,我的名字是...”、“我的爱好是”和“我的宠物的名字是”在 3 个单独的行上
  • 为什么不能像第一行和第三行一样在第二行使用&lt;&lt; endl;

标签: c++ string oop visual-c++ syntax-error


【解决方案1】:

我想这会给你想要的答案:

#include <iostream>
using namespace std;

int main()
{
    cout << " Hi. My name is blank";
    cout << "\n my hobby is";
    cout << "\n my pet's name is" << endl; 
    return 0;
}

【讨论】:

  • 没有\n有没有办法做到这一点?我们在课堂上没有学到这一点,我们只使用了 end1。我想不通。
  • 我们确实使用了 cin。有没有办法使用 cin 做到这一点?
  • @AmyLee cin 仅用于输入。 cout 仅用于输出。 std::endl 写入 '\n' 然后刷新输出。 cout &lt;&lt; " Hi. My name is blank" &lt;&lt; endl; cout &lt;&lt; "my hobby is" &lt;&lt; endl; cout &lt;&lt; "my pet's name is" &lt;&lt; endl; 适合所有人。
猜你喜欢
  • 2022-09-27
  • 1970-01-01
  • 1970-01-01
  • 2021-02-15
  • 2015-01-21
  • 2019-08-31
  • 1970-01-01
  • 2015-03-14
  • 1970-01-01
相关资源
最近更新 更多