问:编写一个程序,"ble"你不喜欢的单词; 也就是说,你用cin阅读单词并在cout上再次打印它们.如果一个单词是你定义的几个单词之一,你就会写出BLEEP而不是那个单词.(stroustrup的c ++书)
这是我写的代码:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
inline void keep_window_open() { char ch; cin >> ch; }
int main()
{
vector<string> disliked;
disliked.push_back("Broccoli");
disliked.push_back("Carrots");
disliked.push_back("Tomatoes");
disliked.push_back("Asparagus");
vector<string> words;
string word;
while (cin >> word) {
words.push_back(word);
}
for (int i = 0; i < words.size(); ++i) {
cout << words[i] << "\t"; //i used it to see if the program was working
}
for (int j = 0; j < …Run Code Online (Sandbox Code Playgroud) 代码如下:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
inline void keep_window_open() { char ch; cin >> ch; }
int main()
{
string operation;
double num1, num2, val;
cout << "Enter the operation followed by the numbers\n";
cin >> operation >> num1 >> num2 >> endl;
if (operation == "+") {
cout << operation << num1 << num2 << endl;
val = num1 + num2;
cout << val << endl;
}
if (operation == "-") …Run Code Online (Sandbox Code Playgroud) c++ ×2