首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

蹩脚新手请问,这个string统计符合的做法有什么东东之处

2013-07-01 
蹩脚新手请教,这个string统计符合的做法有什么错误之处?#include iostream#include fstream#include

蹩脚新手请教,这个string统计符合的做法有什么错误之处?

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
int count = 0;
string tmpstr = "fsidj.dfsjfio.sdnsn...sfdiosdf.......fada.";

for (int i=0;i<tmpstr.length();i++)
{
if (tmpstr[i] ==".")
{
count++;
}
}

cout << "This string have " << count << endl;

return 0;
}



最近应急抱佛脚要做一个文本处理的小程序,在大学学到的东西基本上交还给老师了,哈哈哈
tmpstr[i] =="."
貌似不是这样来弄的,对吧?
只是想统计一下英文句号有多少个


[解决办法]

#include <QtCore/QCoreApplication>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    int count = 0;
    string tmpstr = "fsidj.dfsjfio.sdnsn...sfdiosdf.......fada.";

    for (int i=0;i<tmpstr.length();i++)
    {
        if (tmpstr.at(i) == '.')
        {
            count++;
        }
    }

    cout << "This string have " << count << endl;

    return a.exec();
}

热点排行