473,379 Members | 1,260 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Inputting Data Into New Objects

I'm doing an assignment for class where I need to create a gradebook.

I have it working well but I'm having a hard time getting student names
inputted with spaces. I am using a pointer to create a new object (to
dynamically size the student array to the size specified by the
teacher).

Here is my code:
string * ps = new string[students];
for(int i = 0; i < students; i++)
sa[i] = new int[assignments];
cout << "\nNow I need you to enter the names of your students\n";
for (int i = 0; i < students; i++) {
cout << "Please enter the name of student " << i + 1 << ": ";
cin >> ps[i];
}

I've tried cin.getline(ps[i]); but that gave me a compiler error (error
C2664). I'm using the Sams book: C++ Primer Plus and I've searched for
a while but can't fine the solution. Can anyone help me with this so I
can enter first and last names of students?

Thanks,

--
Jerry

Nov 22 '05 #1
3 1303

<je*******@gmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
I'm doing an assignment for class where I need to create a gradebook.

I have it working well but I'm having a hard time getting student names
inputted with spaces. I am using a pointer to create a new object (to
dynamically size the student array to the size specified by the
teacher).

Here is my code:
string * ps = new string[students];
for(int i = 0; i < students; i++)
sa[i] = new int[assignments];
cout << "\nNow I need you to enter the names of your students\n";
for (int i = 0; i < students; i++) {
cout << "Please enter the name of student " << i + 1 << ": ";
cin >> ps[i];
}

I've tried cin.getline(ps[i]); but that gave me a compiler error (error
C2664). I'm using the Sams book: C++ Primer Plus and I've searched for
a while but can't fine the solution. Can anyone help me with this so I
can enter first and last names of students?


#include <iostream>
#include <string>

int main()
{
std::string name;
std::cout << "Enter name: ";
std::getline(std::cin, name); /* note: not the same as cin.getline() */
std::cout << "Name is: " << name << '\n';
return 0;
}

-Mike
Nov 22 '05 #2
je*******@gmail.com wrote:
I'm doing an assignment for class where I need to create a gradebook.

I have it working well but I'm having a hard time getting student names
inputted with spaces. I am using a pointer to create a new object (to
dynamically size the student array to the size specified by the
teacher).

Here is my code:
string * ps = new string[students];
for(int i = 0; i < students; i++)
sa[i] = new int[assignments];
cout << "\nNow I need you to enter the names of your students\n";
for (int i = 0; i < students; i++) {
cout << "Please enter the name of student " << i + 1 << ": ";
cin >> ps[i];
}

I've tried cin.getline(ps[i]); but that gave me a compiler error (error
C2664). I'm using the Sams book: C++ Primer Plus and I've searched for
a while but can't fine the solution. Can anyone help me with this so I
can enter first and last names of students?


Simple

getline(cin, ps[i]);

John
Nov 22 '05 #3
That worked. Thanks John! I had a feeling it'd be something easy.

--
Jerry

Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: C G | last post by:
Dear All, I have a text file with data like: 1 2 3 4 5 6 7 8 9 i.e. so I have three columns of numbers. I wish to put this data into a table. However, I do not want it to take up three...
0
by: jasonwong | last post by:
Hi, I was wondering if anyone knows of a way to utilize the Runtime Parser to parse a text box filled with user input code. The user will be inputting HTML and data markup into a textbox that...
4
by: snow.carriers | last post by:
http://www.rafb.net/paste/results/fTQgRW16.html Here's my program so far. This is what I'm trying to do: http://contest-cemc.uwaterloo.ca/ccc/2005/senior/phone.pdf So far it works fine. The only...
1
by: yasin | last post by:
is it possible inputting characters from keyboard by codes.or can we use assemly interrupts in asp.net to press keyboard buttons by code.
0
by: yasin | last post by:
is it possible inputting characters from keyboard by codes.or can we use assemly interrupts in asp.net to press keyboard buttons by code.
5
by: Chris | last post by:
I have a meetings section I'm developing on our intranet. Using PHP/MySQL. Meeting info and Meeting docs reside on 2 related tables in the db. Users may want to upload anywhere from 1 to 10 or...
1
by: Ramper | last post by:
Have a .txt document as: String int int int int int int int
5
by: tim123 | last post by:
Hey. I'm having some issues reading in data from a tab delimited text file. I only want to input numbers, and ideally I'd like it to be able to cope with a line or 2 of text at the top in case...
1
by: tjerhoff | last post by:
Hello, I am pretty new to Access and have a question. I am setting up a database that will track production info. All I want to do is have a FORM that will allow me to input several data fields...
16
by: HypeBeast McStreetwear | last post by:
Hey Guys I have to make a program where it accepts/denies applications into a club. The program should read in information about applicants (None was given so I believe I have to make up some...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.