what does this stanford lirbrary mean? C++ simpio.h getInteger() [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i'm trying to understand this library that stanford uses for their CS course but i can't just use this feature in my CS course back in my home. How do i emulate this feature? i was wondering is this a getline(cin, integer)? or is this something to do with fstream? The reason being, i'm trying to go through the lecture series at UDEMY.
Here is the definition.
int getInteger(string prompt = "");
Reads a complete line from cin and scans it as an integer. If the scan
succeeds, the integer value is returned. If the argument is not a
legal integer or if extraneous characters (other than whitespace)
appear in the string, the user is given a chance to reenter the value.
If supplied, the optional prompt string is printed before reading the
value.
Usage:
int n = getInteger(prompt);

You can download simpio.h here: http://www.eecs.wsu.edu/~cs150/prog/libs.htm
If you can't or don't want to use the library, you could study its source code.

Related

C++ the value of a variable in a string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to make a function that has one parameter (a string that contains the name of a variable in my program) and returns the value that the variable stores.
Unfortunately, C++ doesn't provide a simple mechanism for reflection (the idea that the program can, at runtime, look up variable names by value or the like). You may need to consider using an alternate approach.
For example, you could make a std::unordered_map whose keys represent certain values that you'd like to look up and whose values are populated with the items you'd like to look up.
Hope this helps!

Ignore a block of code that fails c++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Is there a way to just ignore a block of code only if it fails to execute in c++? Something like the try - except in python, it would help me a lot.
I'm trying to make a program that constantly reads some information of a file that contains a number, and then converts it to an integer with stoi().
The problem is that the file is constantly being modified by another program, and at some point the main program may read the file when it is being modified, giving an emty string and making the program fail when trying to convert it to an integer.
What I would like to do is make my program ignore all the loop if the stoi() fails, and simply wait until the loop is executed again to get actualized information. I know that this can be done in python with try and eccept, but I don't know how to do it in c++.
try block associates one or more exception handlers (catch-clauses) with a compound statement.
For more detail please refer try catch in c++

How to split a long input into multiple items in C++? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm new to C++ and have been trying to code a program where I enter many things at once and it splits them into different strings, ints, etc. depending on what they are but I can't figure out how.
I want to be able to input, for example, "What is 7 plus 9?" and code it so it assigns the first number (7) to int a, the second number (9) to int b, recognize the word "plus" to be the operator. This would then go to a simple calculator program which I have already coded fine and would then output the answer.
How do I code it so it can split the entire input into multiple individual items? I was thinking there must be some function for a format of input in which case I could define input as string1, string2, int a, string 3, int b, and just have it know the start/end of each by the spaces. Anything you have in mind that could do this please let me know.
Thanks
ideally a lexer and parser like antlr or lex/yacc would be great but the learning curve is steep

Count char occurs in string with length 10^200 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a string on Linux standard terminal input. Its maximal length is 10^200 (as said in program specification). I have to count, how many "3" characters are inside it (occur in this string). I couldn't do that by for loop, because there is no so big variable type, which can be used as iterator. Is there any way to analyze so big strings?
Is there any way to analyze so big strings?
Not in this universe there is not. Such an entity cannot exist in this universe1 and that which does not exist, cannot be analyzed.
1 Current estimates of this universe's total number of particles particles are in the region of 1080.
As from your comment
The data source is standard terminal input.
Then you'll need a lot of monkeys to type this in.
Though you don't need to read in what's typed at once into a big string, but you can simply analyze char by char as typed. The std::istream::get(char_type& ch) method is suitable for doing so.

In C++ what's the easiest way for a user to enter data going into a 2D array? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want the program to take user input to fill a 2D array of ints and I'm not sure what the easiest format to have the user enter the data would be (easy in terms of programming).
For example in Java I could use .split() to separate integers by spaces or commas etc., but since a string can't easily be broken up in C++, this is a problem.
I don't want to prompt the user each time for each element such as:
enter integer for location 0, 0
enter integer for location 0,10
enter integer for location 2, 0
Here is a stackoverflow answer that talks about how to tokenize a string in C++
How do I tokenize a string in C++?
I haven't tried boost but strtok is pretty easy to use but may have some multithreading issues.