You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <iostream>
# include "CSVReader.h"
using namespace std ;
// 测试按行读取
void testReadByLine ( const string & filename ) {
cout < < " === 测试按行读取 === " < < endl ;
CSVReader reader ( filename ) ;
vector < CSVRow > rows = reader . readByLine ( ) ;
for ( const auto & row : rows ) {
for ( const auto & cell : row . data ) {
cout < < cell < < " " ;
}
cout < < endl ;
}
cout < < " === 按行读取测试结束 === \n " < < endl ;
}
// 测试按块读取
void testReadByBlock ( const string & filename , int blockSize ) {
cout < < " === 测试按块读取(块大小: " < < blockSize < < " 行) === " < < endl ;
CSVReader reader ( filename ) ;
vector < CSVRow > rows = reader . readByBlock ( blockSize ) ;
for ( const auto & row : rows ) {
for ( const auto & cell : row . data ) {
cout < < cell < < " " ;
}
cout < < endl ;
}
cout < < " === 按块读取测试结束 === \n " < < endl ;
}
// 测试按字节读取
void testReadByByte ( const string & filename , int byteSize ) {
cout < < " === 测试按字节读取(字节数: " < < byteSize < < " ) ===" < < endl ;
CSVReader reader ( filename ) ;
string bytes = reader . readByByte ( byteSize ) ;
cout < < " 读取的字节内容: " < < bytes < < endl ;
cout < < " === 按字节读取测试结束 === \n " < < endl ;
}
int main ( ) {
string filename = " example.csv " ; // 测试文件路径
// 测试按行读取
testReadByLine ( filename ) ;
// 测试按块读取
testReadByBlock ( filename , 2 ) ; // 读取 2 行
// 测试按字节读取
testReadByByte ( filename , 10 ) ; // 读取 10 个字节
return 0 ;
}