Question

In: Computer Science

c++ How do I get numbers and words before I press the enter? For example, if...

c++

How do I get numbers and words before I press the enter?

For example, if i type cat 12 Rabbit 27 and then click enter, i want to stop receiving input.

Solutions

Expert Solution

Answer:

To read a single line at once you can use the function getline() in C++.

The use of getline() is demonstrated below.

Sample outputs:

If you want to take inputs and store them as words and numbers separately then you can use two arrays and use for loop to take the input for 'n' numbers of data.

Sample outputs:

I hope i answered your question. Please ask any doubts in comments and rate the answer after your doubts are cleared.


Related Solutions

c++ How do I get it before a particular string when I use <ifstream>? For example,...
c++ How do I get it before a particular string when I use <ifstream>? For example, when it's 'Apple: fruit', I only want to get the previous ':' text (Apple). And then I want to move on to the next row. How can i do?
How do I get my program to ask the user to re enter the correct information...
How do I get my program to ask the user to re enter the correct information if the information entered does not match the database records? When I run my program it does let me know that the information entered does not match the database records but it does not ask me to enter the information again. Please add code (in bold) in the proper area with short explanation package MailMeSQL; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import...
How do I get my program to ask the user to re enter the correct information...
How do I get my program to ask the user to re enter the correct information if the information entered does not match the database records? When I run my program it does let me know that the information entered does not match but it does not ask me to enter the information again. package MailMeSQL; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Scanner; import com.mysql.cj.jdbc.JdbcConnection; public class mailmeMain {    public static void...
In Excel: How do I turn a series of dates into a sequence of numbers (example...
In Excel: How do I turn a series of dates into a sequence of numbers (example 1,2, 3)?
How do I know if my company is going downhill ?(money wise) before I get bankrupt...
How do I know if my company is going downhill ?(money wise) before I get bankrupt because till this day I had no such problem but when the day comes I want to be prepare!!! What should I review or see.?
How do I know if my company is going downhill ?(money wise) before I get bankrupt...
How do I know if my company is going downhill ?(money wise) before I get bankrupt because till this day I had no such problem but when the day comes I want to be prepare!!! What should I review or see.?
a. What is Bitbucket and how do I get there? b. What is Sourcetree? c. How...
a. What is Bitbucket and how do I get there? b. What is Sourcetree? c. How do I get Sourcetree and install it? d. With a lot of details and screen shots show the following with Sourcetree i.Clone a repository from Bitbucket ii.Fetching iii.Pulling iv.Staging v.Committing vii.Pushing
How do i get the code below to add an element before another without making the...
How do i get the code below to add an element before another without making the array off one element? (javascript) public void addBefore(double element) { itemCount++; double data[] = new double[this.data.length]; if(currentIndex <= itemCount) { if(currentIndex != 0) { for(int index = currentIndex; index >= itemCount; index ++) { data[index] = this.data[index]; } currentIndex--; data[currentIndex] = element; } if(currentIndex == 0) { data[0] = element; currentIndex = 0; } } }
if I need to get the sum of 6 numbers, here is a C programming solution...
if I need to get the sum of 6 numbers, here is a C programming solution int getSum(int number1, int number2, int number3, int number4, int number5, int number6); and the function is: int SUM; sum = number1+number2+number3+number4+number5+number6; return SUM; this function is called in main, and the main looks like: int totalSum; totalSum=getSum(1,2,3,4,5,6); while(1); so how can I write this C programming code in ARM assembly code, can you please write the comment of each line so I can...
declare an integer array of n numbers //enter a value for n before the declaration enter...
declare an integer array of n numbers //enter a value for n before the declaration enter values for the declared array, pass the array to the method that has the name "countNumbers" let the function countNumber count how many elements of the array in the interval [70 90] means between 70 and 90 inclusive, returns this count to the main, and prints it using format printing. --------------- Please Solve As soon as Solve quickly I get you thumbs up directly...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT