Assign userstr with a string from user input with the prompt

Assign user_str with a string from user input, with the prompt: \'Enter a string:\ \' Reminder: The \"\ \" is a newline character that is not visible in the output and causes following output to appear on the next line. Note: These activities may test code with different test values. This activity will perform two tests: the first with user input of \"Hello!\", the second with user input of \"3230 Main St.\"

Solution

Using c++

#include<iostream>
#include<string>
using namespace std;

//Main function
int main()
{
//Declare a string to entered data
std::string data;

cout<<\"Enter a string:\ \";
//Accept data till \ (enter key is pressed)
std::getline(std::cin, data);

cout<<\"\ Entered data = \"<<data;
}//End of main

Output 1:

Enter a string:
Hello!

Entered data = Hello!

Output 2:

Enter a string:
3230 Main St.

Entered data = 3230 Main St.

Assign user_str with a string from user input, with the prompt: \'Enter a string:\ \' Reminder: The \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site