在我的小项目中,我想制作一个小程序,我必须存储不限数量的唯一字符串,但用户可以多次输入同一个唯一字符串。但在我的数组中,我只想要唯一的ID保存一次。简单的说,我不想在我的数组中重复数据。我想用C++来做到这一点,但不知何故,我不能得到逻辑?有人可以帮我在这里吗?如何避免在字符串数组中重复输入?
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main(){
string str[100],ch;
int i,j,n;
j=0;n=0;
//str[0]= "a";
do {
getline(cin,ch);
for (i=0;i <j; i++){
if (ch=str[i]){
cout << "duplicate" ;
}
str[i] =ch;
j++;
}
n++;
} while (n =100);
getchar();
}
我小白在C++,所以请帮我在这里
'的std :: unordered_set' –