1. String comparison function int strcmp (char * str1, char * str2) returns 0 when the two strings are the same (while the strcmp of matlab returns 1 ). View Asic code, str1> str2, return value> 0; str1 <0.
2. Use a string stream to convert a string to a number, as shown in the following code segment:
A) numeric to string:
# Include
# Include
String num2str (double I)
{
Stringstream ss;
Ss <I;
Return ss. str ();
}
B) string to numeric:
Int str2num (string s)
{
Int num;
Stringstream ss (s );
Ss> num;
Return num;
}
3. Calculate the data size of the binary file
A) Functions for reading and writing binary files: ifstream if. read (), ofstream of. write ();
B) file stream pointer locating function: if. tellg (), of. tellp ();
C) file stream pointer change function: if. seekg (), of. seekp ();
Function parameters:
Ios: beg displacement calculated from the starting position of the stream ios: cur displacement calculated from the current position of the stream pointer ios: end displacement calculated from the end of the stream
D) Get the file size code:
// Obtaining file size # include const char * filename = "example.txt"; int main () {long l, m; ifstream file (filename, ios: in | ios:: binary); l = file. tellg (); file. seekg (0, ios: end); m = file. tellg (); file. close (); cout <"size of" <filename; cout <"is" <(m-l) <"bytes. \ n "; return 0 ;}
4. String stream member function str
A) stringstream ss;
String temp_str = ss. str (); obtain the string in the string stream buffer.
B) stringstream ss;
String temp_str = "aaa ";
Ss. str (temp_str); assign a value to the string stream.
C) to reuse a stream, clear the empty stream first and use ss. clear ().