字符串和用户输入的C++

问题描述:

我应该从用户,这是随后Ñ词语读的整数Ñ,然后什么之后跟随是由字终止字和标点的序列结束。例如:字符串和用户输入的C++

2 foo d 
foo is just food without the d . END 

Ñ字是从所述第二线被“编校”。所以它会显示为:

*** is just food without the * . 

我想我可以找出编辑部分。我似乎无法弄清楚如何阅读这些文字...任何帮助都非常感谢!

#include <iostream> 
#include <string> 
using namespace std; 

int main() 
{ 
int n; 
cin >> n; 

string *redact = new string[n] 
for(int i = 0; i < n; ++i) 
    cin >> redact[i] // this part works! 

return 0; 
} 
+0

您的代码示例甚至没有编译。 –

+0

@πάνταῥεῖ失踪';'...恐慌? – AntiHeadshot

+3

@AntiHeadshot没有恐慌,只是说明了这一事实。 OP应该发布他们的_real_代码。 –

以下代码将迎合目的。

#include <iostream> 
#include <string> 
#include <set> 

int main() 
{ 
    int n; 
    std::cin >> n; 

    std::set<std::string> redact; 
    std::string word; 
    for(int i = 0; i < n; ++i) 
    { 
    std::cin >> word; 
    redact.insert(word); 
    } 
while(std::cin>> word && word != "END") 
{ 
    if (redact.find(word) == redact.end()) 
     std::cout<<word<<' '; 
} 
std::cout<<'\n'; 
return 0; 
} 

我相信你是一个学习C++,请注意使用点typesafebound-safescope-safe C++。

因此,没有newdelete除非你可以自称为adept。使用C++提供的算法和容器,而不是发明自己的。