Thread: I just can't get() it.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Oh. You're passing a string literal as the delimiter, but it should be a char:
    Code:
    if (!getline(datafile, receive, ','))
    Quote Originally Posted by William Putnam
    Also, the using namespace std is part of a package header file provided by my university's CS department for assignments.
    Ah, then you should keep in mind that whoever wrote this is not familiar with C++ good practices.

    EDIT:

    Actually, come to think of it, you should replace the controlled infinite loop with a while loop:
    Code:
    while (getline(datafile, receive, ',')) {
        data.insert(receive);
    }
    Quote Originally Posted by William Putnam
    And I appreciated the advice on the parameters for the function, but I have the variables being declared a certain way, and this configuration works fine for me. But thanks for the pointers, I will use those in future programs.
    Yeah, because as your programs get bigger and more complex, you will probably find that having your variables in a smaller scope where appropriate makes it easier to reason about your programs, and hence you will write fewer bugs and have an easier time debugging.
    Last edited by laserlight; 05-07-2013 at 10:15 PM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Tags for this Thread