std cin input with spaces

0 votes
#include <string>

std::string input;
std::cin >> input;

The user want to type "Hello World." 

However, cin fails to recognise the space between the two words. 

How do I get Cin to see the entire Hello World?

I'm trying this using structs, and cin.getline doesn't appear to work. 

This is my code:

struct cd
{
    std::string CDTitle[50];
    std::string Artist[50];
    int number_of_songs[50];
};

std::cin.getline(library.number_of_songs[libNumber], 250);

This yields an error. Any ideas?

Aug 11, 2022 in C++ by Nicholas
• 7,760 points
676 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In C++

0 votes
0 answers

What is the easiest way to initialize a std::vector with hardcoded elements?

I can make an array and initialise&nb ...READ MORE

Jun 27, 2022 in C++ by Nicholas
• 7,760 points
420 views
0 votes
0 answers

Can you use "cin" with string?

To enter a string, I was instructed to use gets(str) rather than cin.  In the programme below, though, I can use cin perfectly well.  Could you please tell me if you can use cin?  Please accept my apologies for my poor English.  The application allows you to enter up to five names and then print them on the screen. The code is as follows: #include <iostream> #include <string.h> using namespace std; int main() { ...READ MORE

Jun 27, 2022 in C++ by Nicholas
• 7,760 points
248 views
0 votes
0 answers

How to initialize an std::string with a length?

How can I correctly initialise a string if its length is specified at build time? #include <string> int length = 3; string word[length]; //invalid ...READ MORE

Jul 27, 2022 in C++ by Nicholas
• 7,760 points
971 views
0 votes
1 answer

What data structure is inside std::map in C++?

An associative container is std::map. The standard's ...READ MORE

answered May 31, 2022 in C++ by Damon
• 4,960 points
627 views
0 votes
0 answers

Intersection of two std::unordered_map

I have two std::unordered_map std::unordered_map<int, int> mp1; std::unordered_map<int, int> ...READ MORE

May 31, 2022 in C++ by Nicholas
• 7,760 points
517 views
0 votes
1 answer

Why is "using namespace std;" considered bad practice?

This has nothing to do with performan ...READ MORE

answered Jun 1, 2022 in C++ by Damon
• 4,960 points
649 views
0 votes
1 answer

Easiest way to convert int to string in C++

The C++11 version has introduced the std::stoi ...READ MORE

answered Feb 10, 2022 in Others by Rahul
• 9,670 points
329 views
0 votes
1 answer

Easiest way to convert int to string in C++

C++ adds std::stoi (and variants for each numeric type) and std::to string, which are the C equivalents of atoi and itoa but expressed in terms of std::string #include <string> std::string s = std::to_string(42); Is therefore ...READ MORE

answered Jun 1, 2022 in C++ by Damon
• 4,960 points
1,031 views
0 votes
1 answer

How can I convert a std::string to int?

There are some new convert methods in C++ that convert std::string to a numeric type. As an alternative to str.c str() atoi(str.c str()) atoi(str.c str() you can make use of std::stoi std::stoi ...READ MORE

answered Jun 1, 2022 in C++ by Damon
• 4,960 points
496 views
0 votes
1 answer

How to reverse an std::string?

A reverse function is integrated into C++ and can be used to reverse a string.  This function accepts two parameters: The start iterator for the string The string iterator has come to an end. The following line of code demonstrates how to use this function: #include <iostream> //The library below must be included ...READ MORE

answered Jun 1, 2022 in C++ by Damon
• 4,960 points
363 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP