| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 481 人关注过本帖
标题:为什么会有一段空白在输出字符串前面?
只看楼主 加入收藏
ClarenceC
Rank: 2
等 级:论坛游民
帖 子:54
专家分:18
注 册:2014-1-10
结帖率:87.5%
收藏
已结贴  问题点数:16 回复次数:1 
为什么会有一段空白在输出字符串前面?
fstream executed;
    string file_name("D:\d.txt"); //content is "hello nihao zhongxiaogang clarence hello world"
    executed.open(file_name.c_str());
    vector<string> executed_vec(10);
    set<string> iset;
    string word;
    while(executed>>word)
    {
        executed_vec.push_back(word);
        iset.insert(word);
    }
    for(vector<string>::const_iterator vecp=executed_vec.begin();vecp!=executed_vec.end();++vecp)
    {
        cout<<*vecp<<" ";//why this consequence has a blank stretch in front of string
    }
    cout<<endl;
    for(set<string>::const_iterator setp=iset.begin();setp!=iset.end();++setp)
    {
        cout<<*setp<<" ";//why this has no blank stretch
    }
    cout<<endl;
    return 0;
结果是:[local]1[/local]  为什么会有一段空白在第一排字符串之前呢?
不好意思各位,我不知道怎么没法加上图片。我描述一下:在控制台输出结果中会有一段空白在“hello nihao zhongxiaogang clarence hello world"前,
   "          (前面是一段空白)hello nihao zhongxiaogang clarence hello world"

[ 本帖最后由 ClarenceC 于 2014-3-8 19:06 编辑 ]
搜索更多相关主题的帖子: world nihao hello 字符串 content 
2014-03-08 19:01
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:16 
你这代码瞎扯蛋的吧,比如"D:\d.txt",按理应该是"D:\\d.txt",我不信你用"D:\d.txt"能运行出结果。

关于空格,因为你的代码 vector<string> executed_vec(10); 呀,你预先就给它10个空字符串。自己写的东西都不知道,不会是抄来的吧
2014-03-10 09:04
快速回复:为什么会有一段空白在输出字符串前面?
数据加载中...
 
   



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

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