io

How to do polymorphic IO from either a File or stdin in Rust?

。_饼干妹妹 提交于 2020-02-20 06:44:48
问题 I'm trying to implement a "polymorphic" Input enum which hides whether we're reading from a file or from a stdin. More concretely, I'm trying build an enum that will have a lines method that will in turn "delegate" that call to either a File wrapped into a BufReader or to a StdInLock (both of which have the lines() method). Here's the enum: enum Input<'a> { Console(std::io::StdinLock<'a>), File(std::io::BufReader<std::fs::File>) } I have three methods: from_arg for deciding whether we're

How to do polymorphic IO from either a File or stdin in Rust?

我与影子孤独终老i 提交于 2020-02-20 06:44:03
问题 I'm trying to implement a "polymorphic" Input enum which hides whether we're reading from a file or from a stdin. More concretely, I'm trying build an enum that will have a lines method that will in turn "delegate" that call to either a File wrapped into a BufReader or to a StdInLock (both of which have the lines() method). Here's the enum: enum Input<'a> { Console(std::io::StdinLock<'a>), File(std::io::BufReader<std::fs::File>) } I have three methods: from_arg for deciding whether we're

How to execute console or GUI input as if it was actual Java code?

五迷三道 提交于 2020-02-15 09:48:48
问题 I want to be able to input java commands/code to execute during run-time (during the execution of a "persistent" program) in the same way, or as close as possible, to the same code would be executed if it was present on the source-code for the program (programmed as part of the software), using a GUI element, like jTextArea. The following StackOverflow questions seem to be related, but, along with they'r answers, don't seem to be what i'm looking for. How To Get Input From Console Class In

第8章 IO类

时光总嘲笑我的痴心妄想 提交于 2020-02-14 17:48:01
8.1 IO类 iostream istream, wistream从流中读取数据 ostream, wostream iostream, wiostream读写流 fstream ifstream, wifstream从文件中读取数据 ofstream, wofstream fstream, wfstream读写文件 sstream istringstream, wistringstream从string中读取数据 ostringstream, wostringstream stringstream, wstringstream读写string 为了支持宽字符wchar_t,所有的类型和函数只要以w开始就行。例如:wcin、wcout、wifstream。 8.1.1 IO对象无拷贝或赋值 ofstream out1, out2; out1=out2;//错误,不能赋值和拷贝 由于不能赋值拷贝,所以不能将形参和返回值设置为流类型,通常必须使用引用方式传递和返回流。而且读写IO对象会改变对象状态,所以不能是const。 8.1.2 流的状态 可以通过流对象的rdstate成员函数返回一个iostate类型的值,表征流的当前状态。 badbit,流崩溃 failbit,IO操作失败 eofbit,文件尾 goodbit,没有错误

IO与NIO

和自甴很熟 提交于 2020-02-13 20:51:07
1、区别 IO ①IO面向流,面向流意味着每次从流中读取一个或多个字节,直到读取所有字节,他们没有被缓存在任何地方 ②IO流是阻塞的。当一个线程调用read()或write()时该线程被阻塞,这道有一些数据被读取或者数据完全写入,该线程在此期间不能做任何事情 ③IO基于字节流和字符流进行操作 NIO ①NIO面向缓冲区 ②NIO非阻塞,非阻塞读:一个线程从某通道发送请求读取数据,如果目前没有数据可用,什么不会获取没并且该线程不是保持阻塞状态该县城可以继续做其他事情 非阻塞写也是同一个道理:一个线程请求写入一些数据到某通道,但不需要等待他完全写入,这个线程可以同时可以去做其他事情 线程通常将非阻塞io的空闲时间用于其他通道上执行io操作,所以一个单独的线程可以管理多个输入和输出通道(channel) ③NIO基于Channel和Buffer(缓冲区)进行操作,数据总是从通道读取到缓冲区中,或者从缓冲区写入到通道中 2、NIO核心 NIO核心:channel(通道)、Buffer(缓冲区)、selector   channel:和IO中stream(流)差不多一个等级,只不过stream是单向(比如inputstream、outputstream),而channel是双向,既可以读又可以写       NIO中channel实现有:FileChannel、DatagramChannel

Java IO最详解

泪湿孤枕 提交于 2020-02-13 04:27:38
初学java,一直搞不懂java里面的io关系,在网上找了很多大多都是给个结构图草草描述也看的不是很懂。而且没有结合到java7 的最新技术,所以自己来整理一下,有错的话请指正,也希望大家提出宝贵意见。 首先看个图:(如果你也是初学者,我相信你看了真个人都不好了,想想java设计者真是煞费苦心啊!) 这是java io 比较基本的一些处理流,除此之外我们还会提到一些比较深入的基于io的处理类,比如console类,SteamTokenzier,Externalizable接口,Serializable接口等等一些高级用法极其原理。 一、java io的开始:文件 1. 我们主要讲的是流,流的本质也是对文件的处理,我们循序渐进一步一步从文件将到流去。 2. java 处理文件的类 File,java提供了十分详细的文件处理方法,举了其中几个例子,其余的可以去 Java代码 package com.hxw.io; import java.io.*; public class FileExample{ public static void main(String[] args) { createFile(); } /** * 文件处理示例 */ public static void createFile() { File f= new File( "E:/电脑桌面/jar/files

Java IO最详解

若如初见. 提交于 2020-02-13 03:49:25
初学 Java ,一直搞不懂java里面的io关系,在网上找了很多大多都是给个结构图草草描述也看的不是很懂。而且没有结合到java7 的最新技术,所以自己来整理一下,有错的话请指正,也希望大家提出宝贵意见。 首先看个图:(如果你也是初学者,我相信你看了真个人都不好了,想想java设计者真是煞费苦心啊!) 这是 Java io 比较基本的一些处理流,除此之外我们还会提到一些比较深入的基于io的处理类,比如console类,SteamTokenzier,Externalizable接口,Serializable接口等等一些高级用法极其原理。 一、java io的开始:文件 1. 我们主要讲的是流,流的本质也是对文件的处理,我们循序渐进一步一步从文件将到流去。 2. java 处理文件的类 File,java提供了十分详细的文件处理方法,举了其中几个例子,其余的可以去 Java代码 package com.hxw.io; import java.io.*; public class FileExample{ public static void main(String[] args) { createFile(); } /** * 文件处理示例 */ public static void createFile() { File f= new File( "E:/电脑桌面/jar

(simple example) MPI parallel io writing garbage

爷,独闯天下 提交于 2020-02-08 07:44:04
问题 I am trying to make multiple processes write an integer buffer into a file at the same time using MPI parallel io. To achieve this goal I searched various websites: MPI and Parallel IO Google book search Parallel IO with MPI And I tried to learn their teachings. To test them i created the following simple code in c++: #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <mpi.h> #define BUFSIZE 100 using namespace std; int main(int argc, char *argv[]) { int myrank, buf[BUFSIZE],