这是我目前的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) 有一天,当我问一个问题有人回答道说,如果有人问一个问题,告诉他们正确的方式做到这一点,而不是using namespace std;,我认为是有点怪,因为using namespace std;是方式更容易,但我想我没有现在的我是一个'初学者'编码员,你们知道的更好.
所以我想我的问题是:为什么std::而不是using namespace std;?
谢谢.
我需要一些代码帮助,我希望它做的是能够让电脑"嘟嘟"使用报警功能,即:\一个,但我不知道如何实现它,这样用户可以选择多少次使用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)