C + + Learning notes

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.