C++读取字符串数据的两种方式
程序员文章站
2023-03-30 20:34:37
C++读取字符串数据的两种方式 对于同样的样例输入: ladder came tape soon leader acme RIDE lone Dreis peat ScAlE orb eye Rides dealer NotE derail LaCeS DrIed noel dire Disk ma ......
c++读取字符串数据的两种方式
对于同样的样例输入:
ladder came tape soon leader acme ride lone dreis peat
scale orb eye rides dealer note derail laces dried
noel dire disk mace rob dries
方式1
#define local #include<iostream> using namespace std; int main(){ #ifdef local freopen("data.in","r",stdin); freopen("data.out","w",stdout); #endif string s; while(cin>>s){ cout<<s<<endl; } }
样例输出
ladder
came
tape
soon
leader
acme
ride
lone
dreis
peat
scale
orb
eye
rides
dealer
note
derail
laces
dried
noel
dire
disk
mace
rob
dries
方式2
#define local #include<iostream> using namespace std; int main(){ #ifdef local freopen("data.in","r",stdin); freopen("data.out","w",stdout); #endif string s; while(getline(cin,s)){ cout<<s<<endl; } }
样例输出:
ladder came tape soon leader acme ride lone dreis peat
scale orb eye rides dealer note derail laces dried
noel dire disk mace rob dries
上一篇: flask你一定要知道的上下文管理机制
下一篇: CMDB设计