如何用scanf函数输入string字符串
请问如何使用scanf函数输入string字符串 string s;s.resize(100);
scanf("%s",&s);
这样可以 建议用cin 柿子饼同学 发表于 2022-8-8 13:13
建议用cin
可是cin没有返回值,不能while(cin>>x == 1)这样用 tommyyu 发表于 2022-8-8 13:14
可是cin没有返回值,不能while(cin>>x == 1)这样用
可是
这是字符串啊 柿子饼同学 发表于 2022-8-8 13:33
可是
这是字符串啊
用空格/换行隔开的字符串 tommyyu 发表于 2022-8-8 15:52
用空格/换行隔开的字符串
啥题目 , 我康康 柿子饼同学 发表于 2022-8-8 19:04
啥题目 , 我康康
传送门 tommyyu 发表于 2022-8-8 19:41
传送门
有空格用 getline 吧
不过你的方法是一次读入一个单词 , 看是否相等吧 , 那还是循环吧 柿子饼同学 发表于 2022-8-8 20:03
有空格用 getline 吧
不过你的方法是一次读入一个单词 , 看是否相等吧 , 那还是循环吧
好的 本帖最后由 人造人 于 2022-8-8 22:09 编辑
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <regex>
using std::cin, std::cout, std::endl;
using std::for_each, std::getline;
using std::string, std::vector;
using std::regex, std::smatch;
using std::sregex_iterator;
int main() {
string word; getline(cin, word);
string text; getline(cin, text);
regex pattern("\\b" + word + "\\b", regex::icase);
vector<smatch> result;
for_each(sregex_iterator(text.begin(), text.end(), pattern), sregex_iterator(), [&result](const smatch &s) -> void {result.push_back(s);});
if(!result.size()) cout << -1 << endl;
else cout << result.size() << " " << result.position() << endl;
return 0;
}
人造人 发表于 2022-8-8 22:03
看不懂啊{:10_266:} tommyyu 发表于 2022-8-10 18:17
看不懂啊
哪里看不懂? 人造人 发表于 2022-8-10 18:33
哪里看不懂?
我基本上全看不懂{:10_266:}
还得多学
页:
[1]