Yesterday, I wrote the code as below to seperate every word in a file,and then display. I wrote the sentence more C++ functions,and feel good:)
#include "iostream"
#include "fstream"
#include "vector"
#include "algorithm"
using namespace std;
vector<char> vec_ch;
vector< vector<char> > vecStr;
void process(char* ch)
{
bool bWordBegin = false;
while(*ch)
{
if(*ch != '/x20' && *ch != '/x0D' && *ch != '/x0A' && *ch != '/x09') //not delimerator
{
bWordBegin = true;
vec_ch.push_back(*ch);
}
else
{
if(bWordBegin)
{
vecStr.push_back(vec_ch);
//vec_ch.empty();
vec_ch.clear();
bWordBegin = false;
}
}
ch++;
}
if(bWordBegin)
{
vecStr.push_back(vec_ch);
vec_ch.clear();
}
}
void Output_char(char ch)
{
cout << ch;
}
void Output( vector<char> v1)
{
//for_each(v1.begin(), v1.end(), Output_char);
copy(v1.begin(), v1.end(), ostream_iterator<char>(cout));
cout << endl;
}
void main(void)
{
char ch[500];
ch[0] = '/r';
ch[1] = '/n';
ifstream in("test.txt");
while(in.getline(ch, 100))
{
process(ch);
//cout << ch <<endl;
}
vector< vector<char> >::iterator iterStr;
//typedef void (* fp)(void) pfp;
//pfp pfp1;
//pfp1 = Output;
for_each(vecStr.begin(), vecStr.end(), Output); //pfp1);
}
分享到:
相关推荐
Unit 1: Introduction to Floorplan Manager (FPM) for Web Dynpro ABAP 1 Exercise 1: Create Components Containing the UIBBs for a Floor...91 Exercise 13: Set the Adaptation Context Using the CBA Technique
Take Assessment: Exercise 1: Decoding Lab 分析记录
3 Using the exercise files WebAssembly and Emscripten 4 Overview of WebAssembly 5 Installing Emscripten 6 Installation walk-through 7 Compilation and execution 8 Simple WebAssembly example 9 Building...
Take Assessment: Exercise 1: Decoding Lab secret.cpp文件
Take Assessment: Exercise 1: Decoding Lab English-Analysis
You'll start by understanding the fundamentals of Go, then get a detailed description of the Go data types, program structures, and Maps. After that, you'll learn how to use Go concurrency idioms to ...
Exercise 1: 本实验是模拟操作系统的磁盘寻道方式,运用磁盘访问顺序的不同来设计磁盘的调度算法。 Exercise 2: 实现的磁盘调度算法有FCFS,SSTF,SCAN,CSCAN和 NStepSCAN算法。 Exercise 3: 设定开始磁道号寻道...
Exercise 1: 设定系统中有五个进程,每一个进程用一个进程控制块表示。 Exercise 2: 输入每个进程的“优先数”和“要求运行时间”。 Exercise 3: 为了调度方便,将五个进程按给定的优先数从大到小连成就绪队列。用一...
UFLDL Exercise: Convolution and Pooling 卷积和池化 matlab代码 只需下载训练集和测试集就可以直接运行
讲解线程和进程之间的关系, 线程的处理方式 ,线程模式, 通信模式
Exercise 1: 本实验是模拟操作系统的主存分配,运用可变分区的存储管理算法设计主存分配和回收程序,并不实际启动装入作业。 Exercise 2: 采用最先适应法、最佳适应法、最坏适应法分配主存空间。 Exercise 3: 当一个...
my-exercise:一个基础的2048小游戏
exercise2:练习2与Maven
Exercise 10: Form to Group Elms By Shape 109 Executing Programs Outside of MSC.Patran 111 Spawning Remote Processes 111 Locking a database 113 Using C and Fortran executables to access a MSC.Patran ...
From C to C++ K&R-Style Functions struct malloc and free Turning Structures into Classes setjmp and longjmp Mixing C and C++ Code Summary Programming Exercise 29. C++’s Dustier Corners do/while goto...
icarnegie ssd6 exercise4答案
C++ Primer英文第五版 书上的Exercise答案
Exercise 1:线性回归 Exercise 2:逻辑回归+正则化 Exercise 3:多类别分类+神经网络正向传播 Exercise 4:神将网络 Exercise 5:正则化线性回归+偏差方差分析+多项式回归 Exercise 6:支持向量机 Exercise 7:K-...
exercise2:墨西哥科学基金会,墨西哥数据咨询公司