相关疑难解决方法(0)

阅读全行输入

我正在尝试存储用户通过控制台输入的输入.所以我需要包括"输入"和任何空格.

但是cin在第一个空间之后停止给我输入.

有没有办法在按下CTRL + Z之前读取整行,或者什么?

c++

21
推荐指数
2
解决办法
7万
查看次数

C ++比较一个字符串的索引和另一个字符串?

如何比较字符串中的单个字符和另一个字符串(可能大于或小于一个字符)

这个程序给了我近300行随机错误。错误也没有引用特定的行号,只是有关“ char *”,“”或“ std :: to_string”的很多东西。

#include <iostream>
#include <string>

using std::cout;
using std::string;

int main() {
    string str = "MDCXIV";
    string test = "D";

    if (test == str[4]) {     // This line causes the problems
        cout << test << endl;
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ string stdstring

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

错误:对于'范围'[-fpermissive],'''的名称查找已更改为ISO'

问:编写一个程序,"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)

c++

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

标签 统计

c++ ×3

stdstring ×1

string ×1