files

Thanks!
Last edited on
your example is not using getline, thus you only get the first word.

http://www.cplusplus.com/reference/string/string/getline/
Last edited on
Can you only use getline with strings or can it be used with c-strings? For this assignment I cannot use strings and can only use c-strings or in other words character arrays.
Hmmm I am not sure how to approach this anymore. We haven't learned how to use the std:: thing I see everywhere so I cannot use that. Is there another way to do this?
The example from cplusplus.com, with an added using namespace std ; directive,
and sanitised to avoid the use of magic numbers:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std ;

int main () {

    const std::size_t NAME_SIZE = 256 ;
    char name[NAME_SIZE] ;
    cout << "Please, enter your name: ";
    cin.getline( name, NAME_SIZE );

    const std::size_t TITLE_SIZE = 256 ;
    char title[TITLE_SIZE];
    cout << "Please, enter your favourite movie: ";
    cin.getline( title, TITLE_SIZE );

    cout << name << "'s favourite movie is " << title << '\n' ;
}
Ok so apparently you can use cin.getline to work with cstrings. Heres the issue. Im working on a function that will fill each index of the array with my different structs. But im getting a "no matching member for call to 'getline'".
Last edited on
Anybody have any clue on why this code isnt working?
Try

getline(myfile, arr[i].name, ',');
Last edited on
No still get that no matching function error using that. Plus im pretty sure getline is for strings while cin.getline is for cstrings.
Rather
1
2
3
4
// From myfile, read characters into arr[i].name until either
// name_size characters have been extracted; or
// a comma is reached
myfile.getline(arr[i].name, name_size, ',');

http://en.cppreference.com/w/cpp/io/basic_istream/getline

Next time, please read the reference before posting.
Last edited on
Thank you!
Please DON'T delete your question after getting your answer. It makes this thread useless as a learning resource for other people. It's a selfish abuse of these forums.

Please go back and edit your post to restore the original question.
Topic archived. No new replies allowed.