[prog] using strings in C++
Marize Pommot-Maia
marize at pommot.net
Mon Feb 21 04:23:18 EST 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Wolf Rising wrote:
| Changed this part to use cin.getline, any ideas on how to get the
| print out to work correctly?
| Thank you !!
|
| while (cdCount < LIBRARY_SIZE) {
| cout << "Enter CD Information: (-1 to quit)" << endl;
| cout << "Enter year: ";
| cin >> year;
| if (year == -1) { break; }
|
| cout << "Enter artist: ";
| cin.getline(artist,SIZE);
| //cin >> artist;
| cout << "Enter title: ";
| cin.getline(title,SIZE);
| //cin >> title;
| cout << "Enter genre: ";
| cin.getline(genre,SIZE);
| //cin >> genre;
|
Hi again,
OK, if you want to use "cin.getline" then the data type has to be
changed to "char". Here's a simple example of how it works:
#include<iostream>
using namespace std;
int main() {
~ int SIZE=80;
~ char sentence[SIZE];
~ cout << "Tell me something: " << endl;
~ cin.getline(sentence,SIZE);
~ cout << "\t What you said: \n" << sentence << endl;
~ return 0;
}
Let me know if it solves your problem.
- --
- ------------------------------------------------------------------------
Marize Pommot-Maia
marize at pommot.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCGMeG4y2uvMn0AkcRAo4KAJ9QSFD3l3X/dPdJMkYlVMwFri7xJwCglu0K
ubIARcVdrxuMF6bIqQyQy0k=
=uXug
-----END PGP SIGNATURE-----
More information about the Programming
mailing list