First, yours may not compile. There are a number of errors:
void main() is non-standard. main() always returns int , and the only portable declarations of main() are int main() and int main(int argc, char* argv[]) (or int main(int argc, char** argv) , which are identical to the previous one, and, of course, the names of these two arguments can be freely chosen).- The
get() and getline() member function that you use takes at least one additional argument: the size of the available buffer.
For the rest of the answer, I assume these errors are fixed.
Of course, the entry does not "skip over the first question." Instead, it reads input that has already been specified, but which you probably didnβt think it was: formatted input using >> stops reading immediately after the completion of its corresponding format (or crash). For example, when reading an integer, it stops when an insignificant digit is encountered. Thus, when reading int for repetam input stream stops reading after the last digit when it encounters a new line used to complete this input. Calling get() calls the string (up to the first). When entering repetam , a new line was entered, and thus this line is a new line, where get() stops.
The more general, when mixing formatted input (i.e. using >> ) and unformatted input (i.e. using the named functions get() , getline() , read() , etc.), you usually you need to remove unwanted characters. In your example, you probably want to get rid of the first new line before calling get() (you need to include <limits> to access std::numeric_limits ):
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); std::cin.get(pointer[i].artist, 50);
If your artisti line does not start with a space character, you can use
(std::cin >> std::ws).get(pointer[i].artist, 50);
The std::ws manipulator skips all leading spaces (it skips spaces, tabs, linefeeds, etc.) and is somewhat easier to enter. Of course, if you often need to ignore newlines, you can create a manipulator to ignore the characters before and including the newline:
std::istream& skipline(std::istream& in) { return in.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); }
However, I think you really did not want to use get() , because this function includes the separation character ( '\n' by default) in the string. You probably want to use getline() . In addition, with std::string it is easier to process character arrays, i.e. I would use a different definition for struct :
struct melodi { std::string artist; std::string titlu; int an; int lungime; };
Thus, strings can be of arbitrary size and not limited to 49 characters (your version should have space for a terminating null character). To read std::string you need a non-member function std::getline() ):
std::getline(std::cin >> skipline, artist);