用C语言编写程序完成以下的UnixLinux系统的系统调用

用C语言编写程序完成以下的UnixLinux系统的系统调用,第1张

//这个是我学Unix C++时对知识点总结程序,应该对和仿你有些用吧。

/*

istreamostream

| \ / |

ifstreamiostreamofstream

|

fstream

*/

#include <iostream>

#include <fstream>

using namespace std

int main()

{

char ch[6]

cout <<"Input a line: "

ch[5] = cin.peek()

cout <<"Peek first char: " <<ch[5] <<endl

cin.get(ch[4])

cout <<"Read first char: " <<ch[4] <<endl

cin.putback(ch[4])

cin.getline(ch, 5)

if(!cin)

{

cout <<"Input error!!!" <<endl

cin.clear()

cin.ignore(100, '\n')

}

else

cout <<ch <<endl

cout <<left <<hex <<showbase <唤旁纤<uppercase <<1234 <<endl

cout <<scientific <<uppercase <<left <<0.00123456 <<endl

cout.fill('*')

cout.width(8)

cout.unsetf(ios::dec | ios::oct)

cout.setf(ios::hex | ios::showbase | ios::uppercase | ios::left)

cout <<1234 <<endl

cout.setf(ios::dec)

ofstream fout("data.txt") //使用fstream fio("data.txt", ios::in | ios::out)既可读又可写。

if(!fout.fail())

{

fout <<"3.14159\t64I love C++" <<endl

fout.put('M')

fout.put('\n')

double d = 0.0123456789

fout.precision(4)

fout.setf(ios::fixed)

//fout.setf(ios::scientific | ios::uppercase)

fout <<d <<endl

fout.seekp(3, ios::cur) //读使用seekg(),与seekp()类似

fout <<'*' <<flush

fout.seekp(3, ios::cur)

fout <<endl

fout.seekp(2, ios::cur)

fout <<'@' <<' ' <<启岁 '*' <<' ' <<'@' <<endl

fout.seekp(2, ios::cur)

streampos j = fout.tellp()

while((fout.tellp()-j) <5)

fout <<'*' <<flush

cout <<"文件写入成功!" <<endl

}

else

cout <<"文件打开失败!" <<endl

fout.close()

ifstream fin

fin.open("data.txt", ios::in) //类似可以如fout那样定义

if(!fin.fail())

{

double d

char ch[20] = {0}

string str

fin >>d

cout <<d <<endl

fin.get(ch[0])

for(int i=0i<2i++)

{

fin.get(ch[i])

}

cout <<ch <<endl

while(!fin.eof())

{

fin.getline(ch, 20, '\n')

cout <<ch <<endl

}

}

else

cout <<"文件打开失败!" <<endl

fin.close()

ofstream fo

fo.open("bin.bin", ios::binary|ios::app)

if(!fo.fail())

{

int a[10]

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

a[i] = i

fo.write((char *)a, sizeof(a))

}

else

cout <<"文件打开失败!" <<endl

fo.close()

ifstream fi

fi.open("bin.bin", ios::binary|ios::in)

if(!fi.fail())

{

int a[10]

fi.read((char *)a, sizeof(a))

fi.close()

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

cout <<a[i]

cout <<endl

}

else

cout <<"文件打开失败!" <<endl

fi.close()

return 0

}

用锋念system函数简单调用ping命令:

#include "stdio.h"

void main()

{

char ip[15]

char command[50]

// printf("enter IP please: ")

scanf("%s"银笑困,&ip[0])//输入要ping的ip

sprintf(command,"升瞎ping %s",ip)

system(command)

exit(0)

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12542594.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存