我想有 2 个字符串作为输入,这样我就可以使用getline(cin,s)
(所以我可以选择整行直到'\n'
)然后我想搜索第二个数组,如果它包含第一个数组的单词而不使用string::find()
or strstr()
。但我仍然找不到将字符串转换为数组的方法
int main()
{
string s;
string s2;
char array[50];
char array2[50];
cout<<"Give me the first word"<<endl;
getline(cin,s);
cout<<"Give me the text"<<endl;
getline(cin.s2);
array=s;
array2=s2;
}
我想的第二种方法是从一开始就使用数组来完成这项工作:
char array[50];
cin.getline(array,50);
但是,如果我使用直接数组,有什么方法可以像在字符串上一样找到数组的长度吗?
//example
string s;
int x;
getline(cin,s);
x=line.length();