| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5549 人关注过本帖
标题:Strings with spaces? 字串符带空格
只看楼主 加入收藏
点线面
Rank: 8Rank: 8
来 自:NO.-1
等 级:蝙蝠侠
帖 子:525
专家分:980
注 册:2011-1-3
结帖率:100%
收藏
 问题点数:0 回复次数:3 
Strings with spaces? 字串符带空格
This is my program:
这是我的程序
 #include <iostream>

using namespace std;

int main()
{

      string name;
      
      cout << "Welcome, What is your name?" << endl;
      cin >> name;
      cout << name << endl;
   
}
 



When you enter strings with a space, it doesn't print out the part of the string after the space. Why? I'm pretty new to C++ and I can't figure this out.
 当你输入带有空格字符串时,它不能输出空格后面的字符串.为什么?C++很东西我不是很明白
 
Disch (4163)     Jan 7, 2011 at 10:02am
Because >> stops at whitespace.
因为>>因空格停止

If you want the whole line, use getline:
如果你想输出整行,用getline

 //  cin >> name;  // bad
getline(cin,name);  // good
 
有什么建意可以发表一下
搜索更多相关主题的帖子: after 字符串 
2011-01-07 10:16
alwaysfocus
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:25
专家分:138
注 册:2010-12-15
收藏
得分:0 
嗯,挺好,LZ继续努力!
2011-01-07 10:30
点线面
Rank: 8Rank: 8
来 自:NO.-1
等 级:蝙蝠侠
帖 子:525
专家分:980
注 册:2011-1-3
收藏
得分:0 
慢慢步,不停步,大踏步

小代码,大智慧
2011-01-07 10:55
chuanglan
Rank: 2
等 级:论坛游民
威 望:2
帖 子:91
专家分:29
注 册:2012-8-14
收藏
得分:0 
Are you fimiliar with C language? If so,it's not difficult to understand that "scanf" will terminate its input when come across a space.so maybe is the same in C++ language,I'm sorry that I am a C++ self-learner,I  cannot solve this matter either.
2012-10-28 11:34
快速回复:Strings with spaces? 字串符带空格
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018107 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved