Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8108637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:10:34+00:00 2026-06-06T01:10:34+00:00

In C++, istream& operator>> can be used to read data as in text. What

  • 0

In C++, istream& operator>> can be used to read data “as in text”. What is the equivalent in D?

My attempt:

input.txt

c 1033
90.432

input_test.d

import std.stdio;
import std.stream;

void main()
{
    auto inputFile = new BufferedFile("input.txt");
    char c;
    int i;
    double d;

    inputFile.read(c);
    inputFile.read(i);
    inputFile.read(d);
    writeln(c, '\t', i, '\t', d);
}

Output

c   858796320   4.90559e-62
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:10:36+00:00Added an answer on June 6, 2026 at 1:10 am

    D has lots of ways of reading data from files to make various use cases convenient. Here are some:

    • std.file.read for reading the contents of a file into an untyped array of bytes.
    • std.file.readText for reading the contents of a file into a string.
    • The members of the InputStream interface which you’ve already discovered.
    • std.stdio.file:readln for reading lines from a file. Also see readf in the same structure.
    • std.stdio.file:byLine (also byChunk) for reading lines or arbitrary sized blobs.

    Based on your specific case, you’ll probably want to use slurp or readf. Your other option is to read lines and split them into the fields you want, then use std.conv.to to parse the textual representation:

    double d = to!double(somestring);
    

    In summary, if every line has the same format, slurp is the nicest way to go. Otherwise, you’ll have to decide what will be most convenient for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I read from an std::istream using operator>> ? I tried the following:
I think the following code can be used to create manipulators. #include<iostream> ostream &
I'm using std::getline() to read lines from an std::istream-derived class, how can I move
How do I read in a variable number of characters? The user can input
I am trying to do the following: template <class T> std::ifstream& operator>> (std::ifstream& fin,
void foo(ifstream &ifs) { //do something } int main() { fstream fs(a.txt, fstream::in); foo(fs);
template<typename T> class ClassVariantVisitor : public boost::static_visitor<T> { public: T operator()(int& i) const {
In the following code: #include <iostream> template <typename T, size_t N> void cal_size(T (&a)[N])
This is the C++ code: #include<iostream> using namespace std; int a=8; int fun(int &a)
I've got raw data streams from image files, like: vector<char> rawData(fileSize); ifstream inFile(image.jpg); inFile.read(&rawData[0]);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.