Jecho

导航

2013年5月10日 #

使用ifstream和getline读取文件内容[c++]

摘要: #include<iostream>#include<fstream>#include<string>usingnamespacestd;//输出空行voidOutPutAnEmptyLine(){cout<<"\n";}//读取方式:逐词读取,词之间用空格区分//readdatafromthefile,WordByWord//whenusedinthismanner,we'llgetspace-delimitedbitsoftextfromthefile//butallofthewhitespacethatsepar 阅读全文

posted @ 2013-05-10 18:50 Jecho 阅读(432) 评论(0) 推荐(0) 编辑

深入了解scanf/getchar/gets/cin等函数(转载)

摘要: scanf(), getchar()等都是标准输入函数,一般人都会觉得这几个函数非常简单,没什么特殊的。但是有时候却就是因为使用这些函数除了问题,却找不出其中的原因。下面先看一个很简单的程序:程序1: #include <stdio.h> int main() {char ch1, ch2;scanf("%c", &ch1);scanf("%c", &ch2);printf("%d %d/n", ch1, ch2);return 0; } 或者是: #include <stdio.h> int 阅读全文

posted @ 2013-05-10 17:16 Jecho 阅读(151) 评论(0) 推荐(0) 编辑

cin.putback

摘要: a='a',b等待你的输入, cin>>a; cin.putback(a); cin>>b 此时a和b都可以读回来a='a',b='a'。 阅读全文

posted @ 2013-05-10 16:12 Jecho 阅读(202) 评论(0) 推荐(0) 编辑

C-style 字符串小示例

摘要: const int n_size=127;char user_name[n_size];cout<<"enter your name:"<<endl;cin>>setw(n_size)>>user_name; //setw();将字符串限制在n_size-1中,若n_size为3,这里如果输进uirtt 只会保留ui(还有一个结束字符),最后一个//是字符串结束符 (#include <iomanip>)cout<<user_name;switch (strlen (user_name)) 阅读全文

posted @ 2013-05-10 11:08 Jecho 阅读(205) 评论(0) 推荐(0) 编辑