File read and write operations
#include <iostream> #include <fstream> #include <string> #include <vector>using namespace std; void Main (int argc, char* argv[]) {ifstream in ("C:\\users\\administrator\\desktop\\c++.txt", ifstream::out); ofstream Out ("C:\\users\\administrator\\desktop\\cc.txt", Ifstream::app); if (!in) {cout<< "Cannot open input file!" <<endl;} String Str;while (Getline (in,str)) {Out.write (Str.c_str (), Str.size ()), Out.write ("\ n", 1);}}
Atoi and ITOA implementations:
#include <iostream>using namespace Std;int atoi (char* ch); char* itoa (int n,char* ch); char* reverse (char* ch); void m Ain (int argc, char* argv[]) {char* ch = "123579"; int a = atoi (ch); Cout<<a<<endl;int n = 752456;char Cc[10];char * C = itoa (N,CC); Cout<<c<<endl;} int atoi (char* ch) {int i = 0;int num = 0;while (ch[i]! = ' + ') {num = num * + ch[i]-' 0 '; i++;} return num;} char* itoa (int n,char* ch) {int i = 0;while (n) {ch[i++] = n% + ' 0 '; n = N/10;} ch[i]= ' + '; return reverse (CH);} char* reverse (char* ch) {int size = 0;while (ch[size]!= ') {size++;} char temp;for (int i = 0, j = size-1; I < J; i++,j--) {temp = Ch[i];ch[i] = ch[j];ch[j] = temp;} return ch;}
Read a set of integers to determine the number of a value
#include <iostream> #include <vector> #include <algorithm>using namespace std;void main (int argc, Char * argv[]) {int num;vector<int> nums;while (cin>>num) {if (num==-1) break;nums.push_back (num);} int number = 5;int times = 0;vector<int>::const_iterator result = Find (Nums.cbegin (), Nums.cend (), number); while ( Result! = Nums.cend ()) {Times++;result++;result = find (Result,nums.cend (), number);} cout<< "Total times of 5 are:" <<TIMES<<ENDL;}
C + + Learning notes