幼功回看,终端对非打字与印刷字符的呈现形式

作者: 关于计算机  发布:2019-11-15

有如下代码:

 

#include <iostream> 
#include <string> 
using namespace std; 
int main(int argc, char** argv) 

    char buffer[32] = {0}; 
    buffer[0] = 0; 
    buffer[1] = 'E'; 
    buffer[2] = 'L'; 
    buffer[3] = 'L'; 
    buffer[4] = 'O'; 
    string s(buffer, 32); 
 
    string b = "hello"; 
    b = s + b; 
    cout << "b:"<<b << endl; 
    cout <<"s.size():"<< s.size() << endl; 
    cout <<"s:"<< s << endl; 
    cout << "s.c_str()"<<s.c_str() << endl; 
 
    return 0; 

运行结果:
b:ELLOhello
s.size():32
s:ELLO
s.c_str()

#include <iostream>

重定向标准输出至一个文件(./a.out > a.txt),用vim打开a.txt,文件内容显示如下:
  1 b:^@ELLO^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@hello        
  2 s.size():32
  3 s:^@ELLO^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
  4 s.c_str()

#include <vector>

 

#include <string>

摘自 积累浅知识的小菜一个--stay hungry, stay foolish

 

#include iostream #include string using namespace std; int main(int argc, char** argv) { char buffer[32] = {0}; buffer[0] = 0; buffer[1] = E; buffer[2] = L; buff...

int main(int argc, const char * argv[]) {

    // insert code here...

    std::cout << "Hello, World!n";

    int a=0;

    std::cout <<(a==0?"a==0":"a!=0");

    int b[10] = {10,3,3,3};

    std::vector<int> c;

    c.push_back(10);

    c.push_back(40);

    c.push_back(33);

    int d=c[0];

    int e=c[1];

    int f=c[2];

    std::cout<<d<<std::endl;

    std::cout<<e<<std::endl;

    std::cout<<f<<std::endl;

    std::cout<<c.size()<<std::endl;

    

    for (int i=0; i<c.size();i++) {

        std::cout<<c[i]<<std::endl;

    }

    

    char str[128]="Hello World";

    char *p="Hello World";

    

    std::string s;

    s="232sdsafdas912::";

    

    s+="dsadsad[[";

    

    

    return 0;

}

 

 

#include <iostream>

 

int main(int argc, const char * argv[]) {

    int max(int x,int y);

    int a,b,c;

    std::cout<<"输入两个数字"<<std::endl;

    std::cin>>a>>b;

    c=max(a, b);

    std::cout<<c;

}

 

int max(int x,int y){

    int z;

    if(x>y) z=x;

    else z=y;

    return z;

}

 

#include <iostream>

using namespace std;

 

class Student{

private:

    int num;

    int score;

public:

    void setdata(){

        cin>>num;

        cin>>score;

    }

    void display(){

        cout<<"num="<<num<<endl;

        cout<<"score="<<score<<endl;

    }

};

Student s1,s2;

int main(int argc, const char * argv[]) {

    s1.setdata();

    s1.display();

    s2.setdata();

    s2.display();

}

 

 

#include <iostream>

using namespace std;

 

class Complex{

public:

    Complex(){real=0;imag=0;}

    Complex(double r,double i){real=r;imag=i;}

    Complex operator + (Complex &c2);

    void display();

private:

    double real;

    double imag;

};

Complex Complex::operator+(Complex &c2){

    Complex c;

    c.real=real+c2.real;

    c.imag=imag+c2.imag;

    return c;

}

void Complex::display(){

    cout<<"("<<real<<","<<imag<<"i)"<<endl;

}

int main(int argc, const char * argv[]) {

    Complex c1(3,4),c2(5,-10),c3;

    c3=c1+c2;

    cout<<"c1=";

    c1.display();

    cout<<"c2=";

    c2.display();

    cout<<"c1+c2=";

    c3.display();

    return 0;

}

 

 

#include <iostream>

#include <fstream>

using namespace std;

 

int main(int argc, const char * argv[]) {

    int a[10];

    ofstream outfile("f1.txt",ios::out);

    if(! outfile){

        cerr<<"open error!"<<endl;

        exit(1);

    }

    cout<<"enter 10 integer numbers:"<<endl;

    for (int i=0;i<10;i++) {

        cin>>a[i];

        outfile<<a[i]<<" ";

    }

    outfile.close();

    return 0;

}

 

本文由金沙澳门官网送注册58发布于关于计算机,转载请注明出处:幼功回看,终端对非打字与印刷字符的呈现形式

关键词: