初学C++,练习代码
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
/*
**简单歌词分析:
**根据开始时间和结束时间 来显示
*/
void readLyric(string fileName);
void analysisOneLine(string str);
void printLyric();
void getLyricHeader(string str);
int changeStringToInt(string str_time);
void timeSort();
const int MAX_LYRIC_LINE_NUM =200;
const int MAX_LYRCE_REPEAT_NUM = 10;
string header[] = {"ai:", "ar:", "al:", "by:"};
int lineNum = 0;
string Lheader[4];
struct OneLineLyric
{
int lineNum;
string startTime;
string endTime;
string lyricContent;
} lyric[MAX_LYRIC_LINE_NUM ]; //动态分配最好
void readLyric(string fileName)
{
ifstream fin;
fin.open(fileName);
if(!fin.is_open())
{
cerr << "文件读取失败!\n";
exit(0);
}
string str;
getline(fin, str);
while(fin)
{
if(str != "")
{
analysisOneLine(str);
}
getline(fin, str)

本文介绍了一位C++初学者通过实践学习,编写代码来解析歌词(LRC)文件的过程,涵盖C++中字符串操作、结构体定义及文件读取等基础知识。
最低0.47元/天 解锁文章
1023





