1.在window下的命令重定向输出到文件里
2.将内容输入到某个文件里的方式:命令<1.txt (使用1.txt中的命令)
3.读取文件里的名,然后将命令读取最后输出到文件里。命令<1.txt>2.txt 这一句的作用就是将运行的命令输入到2.txt中。
4.文件重定向案例1
#include <iostream>
using namespace std;
void main()
{
char str[30] = { 0 };
cin >> str;
cout << str;
system(str);
//输出错误结果
cerr << "enter for you";
cin.get();
cin.get();
}
5.getline()获取一样
#include <iostream>
#include <stdlib.h>
using namespace std;
void main1()
{
char str[10] = { 0 };
//作用是获取一行
cin.getline(str, 10);//限定长度
cout << str;
system("pause");
//比方输入:asdad
//输出结果:asdad
}
//cout.put(ch):输出一个字符,cin.get(ch);获得一个字符
void main()
{
char ch = 0;
while (ch != ' ')//复合表达式
{
cin.get(ch);//等价于ch=cin.get
cin.get();
cout.put(ch); //输出一个字符
}
}
6.屏幕输出流
A:cout.write():控制输出多大长度的字符串
#include<iostream>
#include <iomanip>//控制输出流
using namespace std;
void main()
{
cout.put('A').put('B').put('C').put(' ');
char str[] = "123456789abcdefg";
//通过write输出指定长度的字符串,不包括