欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

C++ read函數(shù)讀入int整形數(shù)據(jù)

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C語言|點(diǎn)擊: 次

Read函數(shù)定義

通過read函數(shù)將文件中的數(shù)據(jù)按照一定的長度讀取出來并且存放在新的數(shù)組中。用于從文件中讀取數(shù)據(jù)。

函數(shù)原型istream& read (char* s, streamsize n);

參數(shù)char* s取出數(shù)據(jù)的流向的char類型數(shù)組指針,streamsize n表示數(shù)組的長度

#include<iostream>
using namespace std;
int read()//read函數(shù)主體部分
{
  int x=0,f=1;char ch=getchar();
  while(ch<'0'||ch>'9')
  {
    if(ch=='-')f=-1;
    ch=getchar();
  }
  while(ch>='0'&&ch<='9')
  {
    x=x*10+ch-'0';
    ch=getchar();
  }
  return x*f;
}
int main()
{
  int n=read()//這就是讀入了n(注意只能用來讀入int類型的數(shù)據(jù),long long還需更改)
  system("pause");
  return 0;
}

Read函數(shù)使用例子

#include <iostream> // std::cout
#include <fstream> // std::ifstream

int main () {

std::ifstream is ("test.txt", std::ifstream::binary);
if (is) {
// get length of file:
is.seekg (0, is.end);
int length = is.tellg();
is.seekg (0, is.beg);

char * buffer = new char [length];

std::cout << "Reading " << length << " characters... ";
// read data as a block:
is.read (buffer,length);

if (is)
std::cout << "all characters read successfully.";
else
std::cout << "error: only " << is.gcount() << " could be read";
is.close();

// ...buffer contains the entire file...

delete[] buffer;
}
return 0;
}

上一篇:C語言中的字符(char)詳細(xì)講解

欄    目:C語言

下一篇:C語言選擇排序算法及實(shí)例代碼

本文標(biāo)題:C++ read函數(shù)讀入int整形數(shù)據(jù)

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/2159.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有