-
Need to print out number of words and lines in a file
My instructor kind of assumed we'd know how to do this. I kind of get the idea, but I don't know what to do with the cstring I generate when I tokenize it.
He said to:
Write a program that prompts the user for the name of a file. Then it opens the file, and counts the number of words and lines in the file, and prints out those counts.
I think I possibly could somehow use a counter to increment using getLIne() until getLine() returns NULL, but the problem is, I'm worried if I try that, a file that looks like this:
Bla bla bla bla bla lkfdljkfaklafdskjladsjkdfkjlkdfjdfshafdsjkjrerjkkjfaddjkfsafkjdjakdfsjkasfjkjkfdskjldfjkfjkdjfkdsakdjfkjfdkjdfskjfdskjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjdfkerea
blkjadkjlfdskjldfkjlfdkjfdjkdfsjkldfskljfksfdljfd
Only register four lines and not get the one after the fourth line.
So I was thinking of something like
Code:
#include <iostream>
#include<ifstream>
#include<cstring>
#include<string>
#include<vector>
#include <cstdlib>
using namespace std;
iostream keyboard;
ifstream file;
iostream cin;
iostream cout;
vector<int> v;
int main()
{
int lineCount = 0;
string filename;
cout << "Enter a file name.";
cin >> filename;
file(filename);
char* ch;
int tempWord = 0;
ch = strtok(line, "%s\");
while (ch != NULL)
{
tempWord++;
}
v.push_back(tempWord);
lineCount++;
while(!file.eof())
{
string line = file.nextLine();
char* ch;
int tempWord = 0;
ch = strtok(line, "%s\");
while (ch !=NULL)
{
tempWord++;
}
v.push_back(tempWord);
lineCount++;
}
cout <<"Line count: " << lineCount;
int total;
for (int i =0; i < v.size(); i++)
{
total = total + v[i];
}
cout << "Word count: " << total;
return 0;
}
Did I do that right?
Will that count the number of words and number of lines correctly?
I really need help now. It's due tomorrow. http://www.javaprogrammingforums.com/yemotions/63.gif
-
Re: Need to print out number of words and lines in a file
I've updated it to this and it's still getting a bunch of errors:
I really need this solved today.
Code:
#include <iostream>
#include<fstream>
#include<istream>
#include<string>
#include<vector>
#include <cstdlib>
#include "string.h"
using namespace std;
iostream keyboard;
ifstream file;
vector<int> v;
int main()
{
int lineCount = 0;
string filename;
cout << "Enter a file name.";
cin >> filename;
file(filename);
string line;
line = file.getline();
char* ch;
int tempWord = 0;
ch = strtok(line, " ");
while (ch != NULL)
{
tempWord++;
}
v.push_back(tempWord);
lineCount++;
while(!file.eof())
{
file >> file.getline();
char* ch;
int tempWord = 0;
ch = strtok(line, " ");
while (ch !=NULL)
{
tempWord++;
}
v.push_back(tempWord);
lineCount++;
}
cout <<"Line count: " << lineCount;
int total;
for (int i =0; i < v.size(); i++)
{
total = total + v[i];
}
cout << "Word count: " << total;
return 0;
}
/usr/include/c++/4.3/istream:801: error: ‘std::basic_iostream<_CharT, _Traits>::basic_iostream() [with _CharT = char, _Traits = std::char_traits<char>]’ is protected
WordCount.cpp:10: error: within this context
WordCount.cpp: In function ‘int main()’:
WordCount.cpp:21: error: no match for call to ‘(std::ifstream) (std::string&)’
WordCount.cpp:24: error: no matching function for call to ‘std::basic_ifstream<char, std::char_traits<char> >::getline()’
/usr/include/c++/4.3/istream:598: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::getline(_CharT*, std::streamsize, _CharT) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.3/istream:409: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::getline(_CharT*, std::streamsize) [with _CharT = char, _Traits = std::char_traits<char>]
WordCount.cpp:27: error: cannot convert ‘std::string’ to ‘char*’ for argument ‘1’ to ‘char* strtok(char*, const char*)’
WordCount.cpp:38: error: no matching function for call to ‘std::basic_ifstream<char, std::char_traits<char> >::getline()’
/usr/include/c++/4.3/istream:598: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::getline(_CharT*, std::streamsize, _CharT) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.3/istream:409: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::getline(_CharT*, std::streamsize) [with _CharT = char, _Traits = std::char_traits<char>]
WordCount.cpp:42: error: cannot convert ‘std::string’ to ‘char*’ for argument ‘1’ to ‘char* strtok(char*, const char*)’
-
Re: Need to print out number of words and lines in a file
Quote:
Originally Posted by
jedipenguin
I really need this solved today.
Never mention your time frame. Your post is no more important or urgent than any other post.
Code:
#include <iostream>
#include<fstream>
#include<istream>
#include<string>
#include<vector>
#include <cstdlib>
#include "string.h"
using namespace std;
iostream keyboard;
I have never heard of this type called "iostream", and neither has the compiler (your very first error). There is a header called <iostream>, but there is no such type.
Regards,
Paul McKenzie
-
Re: Need to print out number of words and lines in a file
When I removed that from the header, it could no longer figure out what cin and cout are. As I said, I've very little knowledge of C++ and am quite furious, if more with the instructor for daring to give us the difficult assignment, especially as this isn't a C++ course even, than with anyone else.
I cooled down a bit and was able to eliminate some of the errors. Actually, there is most definitely a legal include like:
#include<iostream>
I've had it legally in other C++ classes that I wrote before.
Now I have these left as errors:
WordCount.cpp: In function ‘int main()’:
WordCount.cpp:23: error: no match for call to ‘(std::ifstream) (std::string&, const std::_Ios_Openmode&)’
WordCount.cpp:26: error: no matching function for call to ‘std::basic_ifstream<char, std::char_traits<char> >::getline()’
/usr/include/c++/4.3/istream:598: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::getline(_CharT*, std::streamsize, _CharT) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.3/istream:409: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::getline(_CharT*, std::streamsize) [with _CharT = char, _Traits = std::char_traits<char>]
WordCount.cpp:41: error: no matching function for call to ‘std::basic_ifstream<char, std::char_traits<char> >::getline()’
/usr/include/c++/4.3/istream:598: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::getline(_CharT*, std::streamsize, _CharT) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.3/istream:409: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::getline(_CharT*, std::streamsize) [with _CharT = char, _Traits = std::char_traits<char>]
-
Re: Need to print out number of words and lines in a file
Ok, it's nearly there, but what's wrong now?
Code:
#include<fstream>
#include<istream>
#include<string>
#include<vector>
#include<iostream>
#include<stdio.h>
#include "string.h"
using namespace std;
ifstream keyboard;
ifstream& file;
vector<int> v;
int main()
{
string& str;
int lineCount = 0;
char* filename;
cout << "Enter a file name.";
cin >> filename;
file(filename, ifstream::in);
char* line;
file = getline(file, str );
char* ch;
int tempWord = 0;
ch = strtok(line, " ");
while (ch != NULL)
{
tempWord++;
}
v.push_back(tempWord);
lineCount++;
while(!file.eof())
{
file = getline(file,str);
char* ch;
int tempWord = 0;
ch = strtok(line, " ");
while (ch !=NULL)
{
tempWord++;
}
v.push_back(tempWord);
lineCount++;
}
cout <<"Line count: " << lineCount;
int total;
for (int i =0; i < v.size(); i++)
{
total = total + v[i];
}
cout << "Word count: " << total;
return 0;
}
WordCount.cpp:12: error: ‘file’ declared as reference but not initialized
WordCount.cpp: In function ‘int main()’:
WordCount.cpp:17: error: ‘str’ declared as reference but not initialized
WordCount.cpp:24: error: no match for call to ‘(std::basic_ifstream<char, std::char_traits<char> >) (char*&, const std::_Ios_Openmode&)’
WordCount.cpp:27: error: no match for ‘operator=’ in ‘file = std::getline [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((std::basic_istream<char, std::char_traits<char> >&)(&((std::ifstream*)file)->std::basic_ifstream<char, std::char_traits<char> >::<anonymous>)), ((std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)((std::string*)str)))’
/usr/include/c++/4.3/iosfwd:86: note: candidates are: std::basic_ifstream<char, std::char_traits<char> >& std::basic_ifstream<char, std::char_traits<char> >::operator=(const std::basic_ifstream<char, std::char_traits<char> >&)
WordCount.cpp:42: error: no match for ‘operator=’ in ‘file = std::getline [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((std::basic_istream<char, std::char_traits<char> >&)(&((std::ifstream*)file)->std::basic_ifstream<char, std::char_traits<char> >::<anonymous>)), ((std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)((std::string*)str)))’
/usr/include/c++/4.3/iosfwd:86: note: candidates are: std::basic_ifstream<char, std::char_traits<char> >& std::basic_ifstream<char, std::char_traits<char> >::operator=(const std::basic_ifstream<char, std::char_traits<char> >&)
-
Re: Need to print out number of words and lines in a file
Quote:
Originally Posted by
jedipenguin
Now I have these left as errors:
WordCount.cpp: In function ‘int main()’:
WordCount.cpp:23: error: no match for call to ‘(std::ifstream) (std::string&, const std::_Ios_Openmode&)’
Please post your updated code.
What are you trying to do on that line (also, it helps if you showed us where line 23 is, as you didn't post your code, and no one is going to count 23 lines).
Code:
cin >> filename;
file(filename);
Is that how you open a file? So how do you open a file:
http://www.cplusplus.com/reference/iostream/fstream/
I see an open() function. So let's try it:
Code:
cin >> filename;
file.open(filename);
OK, it still is an error, since "filename" is a std::string, and open() requires a const char*. So how do we fix that?
http://www.cplusplus.com/reference/string/string/
I see a c_str() that returns exactly what we want. So adding this all up:
Code:
cin >> filename;
file.open(filename.c_str());
And bingo, this compiles.
All of this information I showed you is available right on the web.
Regards,
Paul McKenzie
-
Re: Need to print out number of words and lines in a file
Perhaps I've altered it since then, but right now it's not compiling.
Code:
#include<fstream>
#include<istream>
#include<string>
#include<vector>
#include<iostream>
#include<stdio.h>
#include<ios>
#include "string.h"
using namespace std;
ifstream keyboard;
ifstream file;
vector<int> v;
int main()
{
string str;
int lineCount = 0;
string filename;
cout << "Enter a file name.";
cin >> filename;
file.open(filename.c_str());
char* line;
file = getline(line, streamsize(10000), str );
char* ch;
int tempWord = 0;
ch = strtok(line, " ");
while (ch != NULL)
{
tempWord++;
}
v.push_back(tempWord);
lineCount++;
while(!file.eof())
{
file = getline(line, streamsize(10000), str);
char* ch;
int tempWord = 0;
ch = strtok(line, " ");
while (ch !=NULL)
{
tempWord++;
}
v.push_back(tempWord);
lineCount++;
}
cout <<"Line count: " << lineCount;
int total;
for (int i =0; i < v.size(); i++)
{
total = total + v[i];
}
cout << "Word count: " << total;
return 0;
}
WordCount.cpp:29: error: cannot convert ‘char*’ to ‘char**’ for argument ‘1’ to ‘__ssize_t getline(char**, size_t*, FILE*)’
WordCount.cpp:44: error: cannot convert ‘char*’ to ‘char**’ for argument ‘1’ to ‘__ssize_t getline(char**, size_t*, FILE*)’
Line 29: file = getline(line, streamsize(100000), str );
Line 44: file = getline(line, streamsize(100000), str );
-
Re: Need to print out number of words and lines in a file
Quote:
Originally Posted by
jedipenguin
Perhaps I've altered it since then, but right now it's not compiling.
Why are you using a char pointer for string data? Why isn't filename of type string?
That's the problem -- you're using a char*.
Code:
string filename;
cout << "Enter a file name.";
cin >> filename;
Again, all of your mistakes are easily worked out by just taking time and seeing what the problem is.
Regards,
Paul McKenzie
-
Re: Need to print out number of words and lines in a file
I'd already figured that one before you posted. However, I'm also getting two more errors:
What's wrong with this bit of code:
file = getline(line, streamsize(100000), str );
WordCount.cpp:29: error: cannot convert ‘char*’ to ‘char**’ for argument ‘1’ to ‘__ssize_t getline(char**, size_t*, FILE*)’
WordCount.cpp:44: error: cannot convert ‘char*’ to ‘char**’ for argument ‘1’ to ‘__ssize_t getline(char**, size_t*, FILE*)’
What's that supposed to mean?
-
Re: Need to print out number of words and lines in a file
Code:
char* line;
file = getline(line, streamsize(10000), str );
Where is the buffer that is supposed to contain the data going to come from?
A char* is just a pointer. It does nothing except point to a character. It doesn't have properties where it will magically create buffers for you.
http://www.cplusplus.com/reference/i...tream/getline/
Look at the example from the link above.
Regards,
Paul McKenzie
-
Re: Need to print out number of words and lines in a file
Still not making sense.
What's wrong?
-
Re: Need to print out number of words and lines in a file
Quote:
Originally Posted by
jedipenguin
Still not making sense.
What's wrong?
What did you get out of that example you saw at the link? Comparing it to your code, what is different about that example?
Honestly, you're not taking your time and look at the clear examples that I posted from that website. The examples show that getline() is a member of the stream class. Second, it shows how to use it. The "cin" is the stream, so what is your stream? Isn't it "file" in your example?
If you get this thing to compile, can you imagine what happens if you try to run it and it doesn't produce the results you want?
Regards,
Paul McKenzie
-
Re: Need to print out number of words and lines in a file
It runs forever.
I figured it out. I was having trouble trying to figure out what to do exactly with the syntax but I got it before you posted. However, it appears to be going into an infinite loop.
I added the line
file.close() and it's still going on forever.
-
Re: Need to print out number of words and lines in a file
Another reason I'm so angry is because if something goes wrong, it's likely I could only get a 60% at best, which I'm taking as a personal insult from the professor. And I feel that that is far too low a grade for all the time I'm spending, hence my anger and impatience.
I've spent all day on this. I could've been doing other assignments.
I've been on this for over 4 hours.
-
Re: Need to print out number of words and lines in a file
Quote:
Originally Posted by
jedipenguin
It runs forever.
I figured it out. I was having trouble trying to figure out what to do exactly with the syntax but I got it before you posted. However, it appears to be going into an infinite loop.
http://stackoverflow.com/questions/5...ines-from-file
You should also have had a small, simple, test program that just opens a file, and reads until the end. Then when you get that working, you concentrate on the other aspects of the program. Trying to get 10 things to work at the same time, and the basics are still not working is not the way to complete assignments.
Also, making small test programs makes asking questions here easier for you. You now know what doesn't work, and the question becomes more targeted, as opposed to "my program doesn't work and here is all of my code".
Regards,
Paul McKenzie
-
Re: Need to print out number of words and lines in a file
Basically you need your program to do two things, count the number of lines and count the number of words in a file. Luckily there is a getline function available. Also, there is a version that takes a filestream and a string. Something like this:
Code:
std::string aLine;
std::ifstream myFile( filename.c_str() );
// To get one line from the file
getline( myFile, aLine )
In the above snippet, aLine will now contain the first line of the file. Now, you need to figure out how many words are in that line. You can use strtok, but I am quite fond of stringstreams. With them I can do something like:
Code:
std::stringstream tempStream( aLine );
std::string temp;
while( tempStream >> temp )
{
// Do something
}
A stringstream provides a nice interface from converting from a string to a stream and back to a string again. What I did above was convert the line into a stream. This lets me have control over parsing, counting, etc.
As Paul has mentioned, learning to use the debugger is vital. Also, Google is your friend. Be sure to examine the examples. Try not to panic. You will save yourself time by spending a little extra up front examining the examples and understanding them. Afterward, if you have a question about an example, then by all means, you can ask.
Finally, with the two things I mentioned here (and, pretty much using just the two things), I would be able to write a program to do your assignment.
I hope this helps you.
-
Re: Need to print out number of words and lines in a file
I've tried that and now I'm getting a segmentation fault. (Right now I'm telling it to use the filename as a command line argument rather than read in to see if it just can't read files.
Code:
#include<fstream>
#include<istream>
#include<string>
#include<vector>
#include<iostream>
#include<stdio.h>
#include<ios>
#include "string.h"
#include<sstream>
using namespace std;
ifstream keyboard;
fstream file;
vector<int> v;
int main(int argc,char *argv[])
{
char* str;
int lineCount = 0;
char* filename;
cout << "Enter a file name. \n";
cin >> filename;
//file.open(filename);
file.open(argv[1]);
if (!file.is_open())
{
cout <<"Could not open file"<<endl;
return -1;
}
cout << "Went here.";
string line;
std::string temp;
getline(file,line);
std::stringstream tempStream(line);
char* ch;
int tempWord = 0;
// ch = strtok(line, " ");
while (tempStream >> temp)
{
tempWord++;
}
v.push_back(tempWord);
lineCount++;
cout << "Went here.";
while(!file.eof())
{
getline(file,line);
std::stringstream tempStream(line);
std::string temp;
char* ch;
int tempWord = 0;
// ch = strtok(line, " ");
while (tempStream >> temp)
{
tempWord++;
}
v.push_back(tempWord);
lineCount++;
}
file.close();
cout <<"Line count: " << lineCount;
int total;
for (int i =0; i < v.size(); i++)
{
total = total + v[i];
}
cout << "Word count: " << total;
return 0;
}
It's getting as far as the line that asks for the file name and after that is read in, it says "Segmentation fault." and ends abnormally.
I'm assuming it's probably something wrong with my vector, but what am I doing wrong?
Also, should the filename be of type
char*
or of type
string?
-
Re: Need to print out number of words and lines in a file
-
Re: Need to print out number of words and lines in a file
Ok, I removed the file in and now it works somewhat. However, why is my word count like - 1 billion?
Also, why would my file read thing cause a segmentation fault?
Code:
#include<fstream>
#include<istream>
#include<string>
#include<vector>
#include<iostream>
#include<stdio.h>
#include<ios>
#include "string.h"
#include<sstream>
using namespace std;
ifstream keyboard;
fstream file;
vector<int> v;
int main(int argc,char *argv[])
{
char* str;
int lineCount = 0;
//char* filename;
cout << "Enter a file name. \n";
//cin >> filename;
if (argc!=2)
{
cout <<"Please enter file name."<<"\n";
return -1;
}
//file.open(filename);
file.open(argv[1]);
if (!file.is_open())
{
cout <<"Could not open file"<<"\n";
return -1;
}
string line;
std::string temp;
getline(file,line);
std::stringstream tempStream(line);
char* ch;
int tempWord = 0;
// ch = strtok(line, " ");
while (tempStream >> temp)
{
tempWord++;
}
v.push_back(tempWord);
lineCount++;
while(!file.eof())
{
getline(file,line);
std::stringstream tempStream(line);
std::string temp;
char* ch;
int tempWord = 0;
// ch = strtok(line, " ");
while (tempStream >> temp)
{
tempWord++;
}
v.push_back(tempWord);
lineCount++;
}
file.close();
cout <<"Line count: " << lineCount;
cout <<"\n";
int total;
for (int i =0; i < v.size(); i++)
{
total = total + v[i];
}
cout << "Word count: " << total;
cout <<"\n";
return 0;
}
Also, there are 6 lines, not 7. How do I fix that?
Line count: 7
Word count: -1218673904
-
Re: Need to print out number of words and lines in a file
Quote:
Originally Posted by
GCDEF
I'm unsure of whether I should be using the fstream getline or the global getline.
-
Re: Need to print out number of words and lines in a file
Quote:
Originally Posted by
jedipenguin
Ok, I removed the file in and now it works somewhat. However, why is my word count like - 1 billion?
Please debug your code. If you did that, the error is obvious:
Code:
int total;
for (int i =0; i < v.size(); i++)
{
total = total + v[i];
}
What is the value of "total" before the loop is executed? Didn't you see that when you debugged your code? (you're responsible for debugging your own code).
Also, please use proper indentation.
Code:
#include<fstream>
#include<istream>
#include<string>
#include<vector>
#include<iostream>
#include<stdio.h>
#include<ios>
#include "string.h"
#include<sstream>
using namespace std;
ifstream keyboard;
fstream file;
vector<int> v;
int main(int argc,char *argv[])
{
char* str;
int lineCount = 0;
cout << "Enter a file name. \n";
if (argc!=2)
{
cout <<"Please enter file name."<<"\n";
return -1;
}
file.open(argv[1]);
if (!file.is_open())
{
cout <<"Could not open file"<<"\n";
return -1;
}
string line;
std::string temp;
getline(file,line);
std::stringstream tempStream(line);
char* ch;
int tempWord = 0;
while (tempStream >> temp)
{
tempWord++;
}
v.push_back(tempWord);
lineCount++;
while (!file.eof())
{
getline(file,line);
std::stringstream tempStream(line);
std::string temp;
char* ch;
int tempWord = 0;
while (tempStream >> temp)
{
tempWord++;
}
v.push_back(tempWord);
lineCount++;
}
file.close();
cout <<"Line count: " << lineCount;
cout <<"\n";
int total;
for (int i =0; i < v.size(); i++)
{
total = total + v[i];
}
cout << "Word count: " << total;
cout <<"\n";
return 0;
}
Regards,
Paul McKenzie
-
Re: Need to print out number of words and lines in a file
I thought that, like in Java, primitives automatically initialize.
Also, I fixed that and my line count is still 1 too high and I'm still getting a segmentation fault.
Can't indent. Machine doesn't have a C++ compiler other than through the server Exceed on Demand, which I can't figure out how to get it to auto indent.
Netbeams can't recognize a C++ compiler and anyway, I told it to format but the code below was how it formatted it.
Code:
#include<fstream>
#include<istream>
#include<string>
#include<vector>
#include<iostream>
#include<stdio.h>
#include<ios>
#include "string.h"
#include<sstream>
using namespace std;
ifstream keyboard;
vector<int> v;
int main() {
char* str;
int lineCount = 0;
char* filename;
cout << "Enter a file name. \n";
cin >> filename;
//file.open(filename.c_str());
fstream file(filename, fstream::in | fstream::out);
//file.open("file.txt");
//file.open(argv[1]);
string line;
std::string temp;
getline(file, line);
std::stringstream tempStream(line);
char* ch;
int tempWord = 0;
// ch = strtok(line, " ");
while (tempStream >> temp) {
tempWord++;
}
v.push_back(tempWord);
lineCount++;
while (!file.eof()) {
getline(file, line);
std::stringstream tempStream(line);
std::string temp;
char* ch;
int tempWord = 0;
// ch = strtok(line, " ");
while (tempStream >> temp) {
tempWord++;
}
v.push_back(tempWord);
lineCount++;
}
file.close();
cout << "Line count: " << lineCount;
cout << "\n";
int total = 0;
for (int i = 0; i < v.size(); i++) {
total = total + v[i];
}
cout << "Word count: " << total;
cout << "\n";
return 0;
}
-
Re: Need to print out number of words and lines in a file
Quote:
Originally Posted by
jedipenguin
I'm unsure of whether I should be using the fstream getline or the global getline.
The fstream's getline (which is actually inherited from istream) takes a C-style string (char array) as its input destination. This brings along with it all the perils of C-style strings, so I do not recommend it.
The global getline is for use with std::strings, which are much safer and easier to use.