最简单的C++制作家默神器的方法

现在,有许多学校的英语老师为了学生巩固所学重点,布置了家默作业
为了照顾那些父母不在身边的同学,便想要用程序解决该问题。
大家应该都知道Windows中的VBS文件是有朗读功能的。所以为了简单,不装第三方库,今天就得用到它!

上代码:

#include <fstream>
#include <string>
#include <iostream> 
using namespace std;
int main()  
{  
    ifstream in("dicn.txt");  
    ofstream out("start.vbs");  
    string filename;
    string line;
    if(in) // 有该文件  
    {
        while (getline (in, line)) // line中不包括每行的换行符  
        {
            out << "CreateObject(\"SAPI.SpVoice\").Speak \"" << line << "\"" << endl;
            out << "wscript.sleep 1000*8" << endl;//每报一个单词等待时间
        }
        out << "CreateObject(\"SAPI.SpVoice\").Speak \"" << "默写结束" << "\"" << endl;
    }
    else //没有该文件
    {
        cout <<"[Error] No such file" << endl;
    }
    return 0;
}

编译后运行效果为:

dicn.txt中的内容:

economy
departure time
arrival time
travel to the airport
What time should we arrive at the airport?

-----------------------------------

生成出的start.vbs中的内容应该是这样的:

CreateObject("SAPI.SpVoice").Speak "economy"
wscript.sleep 1000*8
CreateObject("SAPI.SpVoice").Speak "departure time"
wscript.sleep 1000*8
CreateObject("SAPI.SpVoice").Speak "arrival time"
wscript.sleep 1000*8
CreateObject("SAPI.SpVoice").Speak "travel to the airport"
wscript.sleep 1000*8
CreateObject("SAPI.SpVoice").Speak "What time should we arrive at the airport?"
wscript.sleep 1000*8
CreateObject("SAPI.SpVoice").Speak "默写结束"

作者亲测,绝对好用!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值