我的方法有问题.我希望它接受一个字符串数组作为它的第一个参数而不是矢量字符串.但是,当我尝试使用一个字符串数组并在main函数中创建一个字符串时,我会遇到各种错误.我不知道是否应该为我的参数或字符串使用指向字符串数组的指针.有帮助吗?
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <sstream>
#include<iostream>
using namespace std;
class UserName
{
public:
string newMember(string* exist, string newname) {
bool found = false;
bool match = false;
stringstream ss;
string result;
string othername;
for(int i = 0; i < exist.size(); i++){
if(exist[i] == newname){
found = true;
break;
}
}
if(found){
for(int x = 1; ; x++){
match = false;
ss.str("");
ss << newname << x; …Run Code Online (Sandbox Code Playgroud)