Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple way to get user (standard user keyboard input) #1920

Closed
mahSource opened this issue Sep 22, 2023 · 1 comment
Closed

Simple way to get user (standard user keyboard input) #1920

mahSource opened this issue Sep 22, 2023 · 1 comment

Comments

@mahSource
Copy link

At a minimum, there should be something similar in grain, akin to this six line C++ program, to get user input. There should be documentation for this write up front in the Guide with a simple hello "name" program that lets the user input their name and it provides a greeting back.

#include <iostream>
int main() {
  std::cout << "\nEnter an integer: ";
  int num{};
  std::cin >> num;
  std::cout << num << " doubled is: " << num * 2 << '\n';
}

Output

Enter an integer: 25
25 doubled is: 50
@ospencer
Copy link
Member

This is possible—it's reading from the stdin file descriptor: i.e. doing https://grain-lang.org/docs/stdlib/sys/file#File-fdRead on https://grain-lang.org/docs/stdlib/sys/file#File-stdin.

You can track the work being done to make it nicer via this issue: #211

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants