zoukankan      html  css  js  c++  java
  • c++流操作

    非缓冲标准出错流对象cerr和缓冲标准出错流对象clog,它们都是来自于ostream类的对象,用于输出错信息。cerr和clog之间的不同之处在于cerr是不经过缓冲区直接向显示器输出有关信息,而clog则是先把信息放在缓冲区,缓冲区满后或遇上endl时向显示器输出。

    转载

    http://www.cnblogs.com/CaiNiaoZJ/archive/2011/08/16/2141367.html

    #include <iostream>
    using namespace std;

    int main()
    {

    cout.put('q');
    cout.put(' ');
    char ch;
    cin.get(ch);

    char str[20];
    cin.getline(str,19,'s');
    cout<<str<<endl;
    return 0;

    }

    cin.getline(字符指针,字符个数,终止标志符);//注:从输入流中读取n-1个字符,赋值给字符数组或字符指针所指的字符数组,最后插入一个字符串结束标志' '。如果在读取n-1个字符之前遇到指定的终止符,则提前结束读取,最后插入一个字符串结束标志' '。

    int main()
    {

    char str[20];

    cin.ignore(6,'f');
    cin>>str;
    cout<<str;
    return 0;

    }

    跳过前六个字符或者遇到指定终止符f,并忽略。取剩余部分。


    int main()
    {
    string str;
    cin>>str;
    cout<<str<<endl;
    return 0;

    }

    默认情况下,输入操作符会忽略先导空白,遇到字符串的空格的时候会停止读入

    get 用法

    char ch;

    cin.get(ch);

    int a=cin.get();

    cout进制输出:

    int main()
    {
    int a=300;
    cout<<oct<<a<<endl;
    cout<<hex<<a<<endl;
    cout<<dec<<a<<endl;

    }

    吧in里的复制到out里

    int main()
    {
    ifstream i("in.txt");
    ofstream o("out.txt");
    string str;
    while(getline(i,str))
    {
    o<<str<<endl;
    }
    }

    读文件中的单词:

    #include <iostream>
    #include<string>
    #include<fstream>
    #include<vector>
    using namespace std;

    int main()
    {
    string filename;
    cout<<"input filename:"<<endl;
    cin>>filename;
    ifstream in(filename.c_str());
    string word;
    vector<string> v;
    while(in>>word)
    {
    v.push_back(word);
    }

    for(int i=0;i<v.size();i++)
    {
    cout<<v[i];
    }
    return 0;
    }

    in》》word是以空格隔开取得字符串的,还有c_str不能省略。。。。制定参数为const *char

  • 相关阅读:
    Azkaban 简介(一)
    大数据平台搭建(Ambari +HDP)
    大数据平台比较-CDH、HDP、CDP
    Kylin 操作使用(六)
    Kylin 安装部署(五)
    Kylin 核心概念(四)
    数据流图
    android:sharedUserId
    Android的uid与UserHandle
    C++ 多态
  • 原文地址:https://www.cnblogs.com/8335IT/p/5860160.html
Copyright © 2011-2022 走看看