-
-
10-24:
0. vector size, each chassis add!
1. windows open dialog. judge file's good or not
2. naming good or bad?
3. clean up the code
4. conclude the technology in the program. such as isstream, string, str pointer..., is there anything better to improve?
- Accessing individual elements by their position index (constant time).
- Iterating over the elements in any order (linear time).
- Add and remove elements from its end (constant amortized time).
-
The developer will create a standalone executable file that will run on a Windows environment. This program will read in a .TXT file that was created by theSwitch Diagnostics, scan for given information, and output a .TXT file containing a picture of the stack. More information will be given in supplied documents.
Doneness criteria:
A program that when used will correctly output a picture of the stackrequirements:
1. The output file should be a text file. The nameof the file should be something like “Picture_of_<input file name>.txt”.
http://hi.baidu.com/sefule/blog/item/9fad370b23b936990b7b821f.html C++ txt文本操作(转于网络)
http://www.fredosaurus.com/notes-cpp/io/readtextfile.html
Reading a text file is very easy using an
ifstream
(input file stream)
http://www.cppblog.com/guogangj/archive/2011/06/08/148257.html ANSI, unicode, UTF-8
http://blog.youkuaiyun.com/hengyunabc/article/details/5914445
C Runtime Library、C++ Runtime Library、Windows API 和 C++标准四者之间的关系
http://jan.newmarch.name/ssw/files/win32.html about API using
interesting case: 1. a stack that has 2 trunk groups
interesting errors: 1. hardware and software not seeing the same number of switches
2. a stack that has 6 chassis however diags only got results form 5 of them.
问题: 1. 用数组还是vector? 2. 用函数实现:originalBuf-->showBuf 还是直接用originalBuf产生输出?
3. linux portable, fstream is best? 4. char vector 截取部分 google search http://wenwen.soso.com/z/q54434239.htm http://www.programfan.com/club/showpost.asp?id=18590
http://www.byvoid.com/blog/cpp-string/
5. fstream and string http://topic.youkuaiyun.com/u/20071023/17/e88b8c46-dc60-4317-86d9-91702d7ee014.html
10-14 today: show all statas overview int the new txt and go on find question. 6. get 10 and 104 and 100(char*) from the linklist and turn into one string 7. from stream, get special section of it to string list.
《C++标准函数库》中说的 有三个函数可以将字符串的内容转换为字符数组和C—string
1. data(),返回没有”\0“的字符串数组 2. c_str(),返回有”\0“的字符串数组 3. copy()
ifstream fin;
fin.open(docName);
char token[128];
while( fin >> token)
{ cout<<token<<"\n";
//split(token);
}
fstream in(filename.c_str());//打开
char str;
vector<char>ivec;
for( ; in.get(str); )
{ //放入向量
ivec.push_back(str);
}
http://ikaruga.name/Technology/ccplusplus/stlCollection.html#text2 vector, list, dequeue
1. 数组的为数必须用 值大于等于1的常量表达式定义,且只能包含整型字面值常量,枚举常量或者用常量表达式初始化的整型const对象,非const变量以及需要到运行阶段才知道其值的const变量都不能用来定义数组的维度;2. 数组的维度必须用 [] 内指定;
3. 显示初始化数组元素的时候用 {} 括起来,成为初始化列表;不管数组在哪里定义,如果其元素为类类型,则自动调用该类的默认构造函数进行初始化,如果该类没有默认构造函数,则必须为该数组的元素提供显式初始化;在函数体外定义的内置数组,其元素全部初始化为1,在函数体内定义的内置数组,无初始化。
4. 如果指定了数组维度,初始化的元素个数不能超过维数值;若小于,内置类型则初始化为0,类类型则调用该类的默认构造函数进行初始化。
5. 数组和vector不同,一个数组不能用另一个数组初始化,也不能将一个数组赋值给另一个数组;
6. 和vector不同,数组不提供 push——back或者其他的操作在数组中添加新元素,数组一经定义就不允许添加新元素;若需要则要充许分配新的内存空间,再将员数组的元素赋值到新的内存空间。
7. 在用下标访问元素时,vector 使用 vector::size_type 作为下标的类型,而数组下标的正确类型则是 size_t;
Vector
Vectors are a kind of sequence container. As such, their elements are ordered following a strict linear sequence.
Vector containers are implemented as dynamic arrays; Just as regular arrays, vector containers have their elements stored in contiguous storage locations, which means that their elements can be accessed not only using iterators but also using offsets on regular pointers to elements.
But unlike regular arrays, storage in vectors is handled automatically, allowing it to be expanded and contracted as needed.
Vectors are good at:
Compared to arrays, they provide almost the same performance for these tasks, plus they have the ability to be easily resized. Although, they usually consume more memory than arrays when their capacity is handled automatically (this is in order to accommodate extra storage space for future growth).
Compared to the other base standard sequence containers ( deques and lists), vectors are generally the most efficient in time for accessing elementsand to add or remove elements from the end of the sequence. For operations that involve inserting or removing elements at positions other than the end, they perform worse than deques and lists, and have less consistent iterators and references than lists.
VECTOR 在频繁的插入和删除 效率比较低,特别如果是大型的对象会增加很多的析构和拷贝
小型的对象和内置数据类型VECTOR 效率还是比较高的,所以如果是小型的对象和内置数据类型 可以用VECTOR 比LIST效率高
除非你有非常频繁的删除插入
Member functions
(constructor) Construct vector (public member function) (destructor) Vector destructor (public member function) operator= Copy vector content (public member function )
Iterators:
begin Return iterator to beginning (public member type) end Return iterator to end (public member function) rbegin Return reverse iterator to reverse beginning (public member function) rend Return reverse iterator to reverse end (public member function)
Capacity:
size Return size (public member function) max_size Return maximum size (public member function ) resize Change size (public member function) capacity Return size of allocated storage capacity (public member function) empty Test whether vector is empty (public member function) reserve Request a change in capacity (public member function)
Element access:
operator[] Access element (public member function) at Access element (public member function) front Access first element (public member function) back Access last element (public member function)
Modifiers:
assign Assign vector content (public member function) push_back Add element at the end (public member function) pop_back Delete last element (public member function) insert Insert elements (public member function) erase Erase elements (public member function ) swap Swap content (public member function) clear Clear content (public member function)
Allocator:
get_allocator Get allocator (public member function )
list:
http://www.diybl.com/course/3_program/c/cxl/20100630/286937.html
Win32: CreateFile, ReadFile, WriteFile SetFilePointer, GetFileSizeEx, FlushFileBuffers C++ Lib: ofstream, ifstream, fstream; open, close, is_open, rdbuf
console application or windows application?
Description: