小编Fuz*_*Ski的帖子

如何使用cin从用户那里读取完整的一行?

这是我目前的C++代码.我想知道如何编写一行代码.我还会使用cin.getline(y)或不同的东西吗?我已经检查过,但找不到任何东西.当我运行它时,它完美地工作,除了它只键入一个单词而不是我需要输出的整行.这是我需要帮助的.我在代码中概述了它.

谢谢你的帮助

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <fstream>

using namespace std;

int main()
{
    char x;

    cout << "Would you like to write to a file?" << endl;
    cin >> x;
    if (x == 'y' || x == 'Y')
    {
        char y[3000];
        cout << "What would you like to write." << endl;
        cin >> y;
        ofstream file;
        file.open("Characters.txt");
        file << strlen(y) << " Characters." << endl;
        file << endl;
        file << y; …
Run Code Online (Sandbox Code Playgroud)

c++ iostream

18
推荐指数
3
解决办法
6万
查看次数

为什么std ::由经验丰富的编码器使用而不是使用命名空间std;?

可能重复:
为什么'使用命名空间std;' 在C++中被认为是一种不好的做法?

有一天,当我问一个问题有人回答道说,如果有人问一个问题,告诉他们正确的方式做到这一点,而不是using namespace std;,我认为是有点怪,因为using namespace std;方式更容易,但我想我没有现在的我是一个'初学者'编码员,你们知道的更好.

所以我想我的问题是:为什么std::而不是using namespace std;

谢谢.

c++ namespaces using-directives std

10
推荐指数
1
解决办法
2347
查看次数

如何让我的程序在循环中发出蜂鸣声?

我需要一些代码帮助,我希望它做的是能够让电脑"嘟嘟"使用报警功能,即:\一个,但我不知道如何实现它,这样用户可以选择多少次使用switch语句时会发出哔哔声,真的会感谢所有的帮助.

#include <iostream>

using namespace std;

int main()
{
    int x;
    int y;

    cout << "Do you want to make your computer beep" << endl;
    cin >> x;
    if (x == 'y' || x == 'Y')
    {
     cout << "How many beeps do you want" << endl;
     switch (y)
     {
      // This is the part i'm stuck on!!!
     }
    }

    cin.ignore();
    cin.get();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
2269
查看次数

标签 统计

c++ ×3

iostream ×1

namespaces ×1

std ×1

using-directives ×1