Trouble W/Getline Algorithm

This is a discussion on Trouble W/Getline Algorithm within the C++ Programming forums, part of the General Programming Boards category; Don't mind the functions you don't see declarations for, I've error checked everything. I just can't see why it seems ...

  1. #1
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Question Trouble W/Getline Algorithm

    Don't mind the functions you don't see declarations for, I've error checked everything. I just can't see why it seems to skip this one part. Where I use getline. Is there something wrong with this algorithm? I'm trying to get the variable to only be defined as that string when it's on the proper line. I do this by using getline and the file open properties. I'm using visual c++ 6.0. Anybody see something that I don't?

    Code:
    bool cortana::name_check()
    {
    	ifstream checkfile("profile.txt");
    	checkfile >> file;
    	checkfile.close();
    	if(file!="")
    	{
    		return true;
    	}
    	else
    	{
    		return false;
    	}
    }
    void cortana::talk()
    {
    	string str;
    	int linenumber=0;
    	bool data=cortana::name_check();
    	if(data==true)
    	{
    		ifstream getinfo("profile.txt");
    		while(linenumber!=3)
    		{
    			getline(getinfo,str,'\n');
    			if(linenumber==1)
    			{
    				botname=str;
    			}
    			if(linenumber==2)
    			{
    				name=str;
    			}
    			linenumber++;
    		}
    		getinfo.close();
    	}
    	if(data==false)
    	{
    		botname=cortana::find_names();
    		name=cortana::find_player();
    	}	
    		system("cls");
    		cout << "Hello, " << name << ". I am " << botname << "." << endl;
    }

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    make sure ur compiler is fully patched up. There was a bug in getline() but it was fixed in a service pack.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Try std::getline() just to make sure the function is correct.

    Kuphryn

  4. #4
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ..

    I tried adding std, no difference and there's nothing i can do if there is an update because I downloaded this.

  5. #5
    nag
    nag is offline
    Registered User nag's Avatar
    Join Date
    May 2002
    Posts
    22
    Try to use getline() twice ,i hope it would work as mentioned by Stoned_Coder there was a bug in getline() !

  6. #6
    _ Munkey01's Avatar
    Join Date
    Dec 2002
    Posts
    280
    I don't know how to fix your problem but why not return 0 and 1 for true and false? Or are you just using it that way for clarity?

  7. #7
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    Don't know if this will solve your problem, but this is a patch to fix that getline function. RoD gave it to me a few days ago & it corrected a problem I was having.

    Find this code in your <STRING > header file (the change is on line 165):

    else if (_Tr::eq((_E)_C, _D))
    {_Chg = true;
    _I.rdbuf()->snextc();
    break; }

    change snextc() to sbumpc() as indicated below:

    else if (_Tr::eq((_E)_C, _D))
    {_Chg = true;
    _I.rdbuf()->sbumpc();//**************changed snextc(); to sbumpc();
    break; }

  8. #8
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Cool rply:

    I fixed the problem, they were scanning the wrong lines. I changed the string file for the future. Thanks for everyone that helped.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Implement of a Fast Time Series Evaluation Algorithm
    By BiGreat in forum C Programming
    Replies: 7
    Last Post: 12-04-2007, 01:30 AM
  2. Trouble Generating Game Algorithm
    By justlivelife15 in forum Game Programming
    Replies: 3
    Last Post: 06-13-2007, 09:58 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21