std::string 是否仅适用于 c++ 中的'std::cin'
Does std::string works only with 'std::cin' in c++
我最近通过在Google上搜索来了解std::substr()
。我看到了这样的代码:
std::string s = "This is an example string";
std::string s1 = s.substr(11, 7);
std::cout << s1 << std::endl;
现在,如果我尝试使用scanf()
函数(而不是使用std::cin
(进行输入,则该程序在运行时崩溃。std::string
不使用scanf()
函数支持?
scanf()
属于C函数家族,该家族是C语言而不是C 的一部分,对std::string
不提供直接支持,而是与Null终止的字符字符串一起工作。
如果您使用的是C ,则通常应该更喜欢std::string
而不是终止终止字符字符串和 printf()
/scanf()
库函数的输入/输出库。
相关文章:
- 在while循环中输入带有std::cin的字符串后,控制台会输出大量胡言乱语
- Problems with std::cin.fail()
- istream std::cin如何修改自定义istream缓冲区
- 在 std::getline 和 std::cin 期间卡在循环中
- C++ 限制或使用户输入不可见 (std::cin)
- 吃完 EOF 后重复使用 std::cin
- 当使用 std::CIN 输入结构时,它会出错
- 如何使 std::istream 从键盘获取输入(如 std::cin)?
- 如何将 std::cin 作为函数的参数传递?
- std::cin不接受输入
- 在C++中使用 std::cin 将字符传递给 int
- 为什么 std::cin 从一开始就不读
- 从 R 控制台获取用户输入:Rcpp 和 std::cin
- 定义宏时与 std::cin C++中的分段错误
- 如何终止 std::cin.get() 的 ''
- 将 istream 转换为 ifstream 时将 std::cin 传递到参数时出现问题
- STD :: cin和Scanf()应用于字符串之间的区别
- 在GLFW应用程序中,std::cin的行为很奇怪
- 如何使用std::cin函数后修复从文件读取的问题
- std::string 是否仅适用于 c++ 中的'std::cin'