用ifstream和strtok函数读取text文件内容时出现了问题

在使用ifstream和strtok函数读取text文件内容时出现了问题
text文本内容如下:

img


一下是本人写的代码:

#include<iostream>
//#include"stdafx.h"
#include <fstream>
#include"string"
using namespace std;
void Readfile()
{
    ifstream ifs;
    ifs.open("Material Propertity.txt");
    if (!ifs.is_open())
    {
        cout << "打开失败" << endl;
        return;
    }
    char buf[1024] = { 0 };
    ifs >> buf;//读取第一行
    while (strlen(buf)>0)//buf中有效字符串不为空
    {
        char *sst = strtok(buf, ":");
        if (sst != NULL)
        {
            sst = strtok(NULL, ":");
            //cout << sst << endl;
            if (sst != NULL)
            {
                cout << sst << endl;
            }
        }
        ifs >> buf;//继续读取下一行
    }
    ifs.close();
}
int main()
{
        Readfile();
    return 0;
}

当鼠标所在行的代码未注释时,运行出现一下故障:

img


当改行代码注释后,却运行无结果

img


求问程序员们这是什么情况?
感谢!

你文本文件中的冒号是全角字符的冒号,改成半角字符,或者搜索代码中的冒号改为全角字符


可以看下cpp参考手册中的 c++-strtok()