1.读入string 需包含头文件:iostream(iostream中包含string)。 方法: 1.读到空格、tab、回车中任意一个结束:直接cin。 2.读一行:getline。 2.兼容(可以读string,也可以读字符数组) 需包含 ...
字符串的输入的主流函数: 一 scanf 二 cin 三 gets 四 getline 五 sscanf 。 一 scanf s ,str 遇见空格或换行就停止。 include lt stdio.h gt int main char str while true scanf s ,str printf s n ,str return 输入: 输出: 二 cin gt gt str 与scanf ...
2012-04-16 15:01 2 4664 推荐指数:
1.读入string 需包含头文件:iostream(iostream中包含string)。 方法: 1.读到空格、tab、回车中任意一个结束:直接cin。 2.读一行:getline。 2.兼容(可以读string,也可以读字符数组) 需包含 ...
(本文针对于NOIP Day1 玩具迷题) (这是弱鸡写的)(字符串用char二维,本质一样的) 在NOIP成功AC了这道题,结果OJ上被string卡了时间,没办法只能用scanf了.....百度看到scanf能读“字符串”??然后理解错了....我就用它读string。。各种程序崩溃 ...
#include<iostream>#include<string>#include<vector>using namespace std;vector<st ...
1.读取char[] View Code 2.读取string View Code ...
#include <stream> #include <string> int main() { string str; getline(cin,str ...
当不支持gets时,getline又比较慢,可以使用scarf("%[^\n]s", str);来读入以换行表示读完的字符串,其中[^char]表示以char为结束。 ...
前言 网上有很多相关博客,或总或全,在做了这道题后,决定总结一下常用字符串读入 只有常用,请不要吹毛求疵 字符串string 1.scanf printf:(不含空格) 输入:dddd;输出:dddd 推荐用char数组读入再赋值给string ...
C语言: #include<stdio.h> 函数:gets(char*) 举例: char a[1000]; gets(a); int len = strlen(a);//获取串长方法 C++: 1.兼容C语言,头文件:#include< ...