I'm trying to get an array of names stored into a data structure, but I keep getting this odd error of C2661
(error C2661: 'std::basic_istream<_Elem,_Traits>::getline' : no overloaded function takes 1 arguments
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
)
I can't figure out how to fix this error, any help would be appreciated.(code included for reference) -
#include <iostream>
-
using namespace std;
-
-
struct StudentRecords
-
{
-
char name;
-
};
-
-
void main()
-
{
-
StudentRecords student[5];
-
for (int s = 0; s < 2; s++)
-
{
-
cout << "Enter student name ----> ";
-
cin.getline(student[s].name );
-
cout << endl;
-
}
5 2389 sicarie 4,677
Recognized Expert Moderator Specialist
So you are using C++, why are you using getline()?
Have you attempted to read the name in with an intermediary value and then assign it afterwards to the struct value?
Ganon11 3,652
Recognized Expert Specialist
A single char cannot hold a name like "Joe", it can only hold a single character like 'J'. So you don't want your struct to be a plain char - at the very least, make it a char* or char[20] or something.
But, as sicarie mentioned, you are using C++, so why not use std::string? Then you can use getline like so: - string myName;
-
getline(cin, myName);
sicarie 4,677
Recognized Expert Moderator Specialist
A single char cannot hold a name like "Joe", it can only hold a single character like 'J'. So you don't want your struct to be a plain char - at the very least, make it a char* or char[20] or something.
But, as sicarie mentioned, you are using C++, so why not use std::string? Then you can use getline like so: - string myName;
-
getline(cin, myName);
Dang, I looked right over that one.
Thanks, Ganon
just watch how you use getline 'cuz it will also include your return keypress.
Ganon11 3,652
Recognized Expert Specialist
Erm...no, it doesn't. The string returned with getline does not include the newline character '\n' - in fact, according to http://www.cplusplus.com/reference/string/getline.html, "If the delimiter is found, it is extracted and discarded, i.e. it is not stored and the next input operation will begin after it."
cin >> operations will leave the newline character in the stream, but still skips it when getting actual input into a variable.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Shane |
last post by:
Hi,
Thanks in advance for the help. I have been to many websites and tried
several solutions to my problem, but have fixed part of it. It's time to
come humbly to the newsgroups for help :-)
...
|
by: Amadeus W. M. |
last post by:
I'm trying to read a whole file as a single string, using the getline()
function, as in the example below. I can't tell what I'm doing wrong.
Tried g++ 3.2, 3.4 and 4.0. Thanks!
#include...
|
by: Jordan Tiona |
last post by:
I can't get this code to work right. It seems to be skipping some of the cin
functions. Can someone help me with this?
ClassTrack.cpp:
#include <iostream>
#include "ClassTrack.h"
using...
|
by: wqyuwss |
last post by:
Hi,
We have several core dumps in our product. These core dump can be
reproduced in the same place. That is system function call
std::basic_istream<char,std::char_traits<char>>::getline. The...
|
by: ComicCaper |
last post by:
Hi all,
I use a quiz program that accepts a text file for questions and answers
in this format:
Question
Answer1 <----is the correct answer. Quiz randomizes answers.
Answer2
Answer3...
| |
by: vermarajeev |
last post by:
Hello everybody,
This is my second query in this post. Firstly thankx to Banfa, for helping me solve my first query.
Here is the code which I have written.
#include<iostream>...
|
by: Martin Jørgensen |
last post by:
Hi,
I've had a introductory C++ course in the spring and haven't programmed in
C++ for a couple of months now (but I have been programmed in C since
january). So I decided to do my conversion...
|
by: cecil258 |
last post by:
Hey everyone... I'm in a beginning C++ class right now and below is the code I've written for my current assignment... What I need to do is put all of the input code (basically the huge chunk of...
|
by: T.Crane |
last post by:
Hi,
I'm new to C++, and I want to open a file, go through it line by line
and pull out specific things on each line. I've written a test bit of
code to try to do this. For some reason what I'm...
|
by: priyajohal |
last post by:
#include<fstream.h>
#include<process.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
#include<ctype.h>
#include<stdio.h>
void setup()
void help();
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |