C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 27th, 2005, 04:34 PM
seanghatch seanghatch is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 64 seanghatch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 45 m 56 sec
Reputation Power: 9
getline argument error

I'm making a small program to read a text file to the console window, and I want to see the spaces so I'm using getline(). When I compile I get this error

c:\Documents and Settings\Sean\My Documents\Visual Studio Projects\lines\readin.cpp(20): error C2664: 'std::basic_istream<_Elem,_Traits>::_Myt &std::basic_istream<_Elem,_Traits>::getline(_Elem *,std::streamsize)' : cannot convert parameter 1 from 'std::ifstream' to 'char *'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]


Code:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

  int main()
    {
		

        string Spaces;
		int close;
		ifstream a;
		
		cout << "Make sure your file is named dict.txt.\n";
		
		a.open("dict.txt");
        while(!a.eof())
        {
              a.getline(a,Spaces);
              cout << Spaces;
        }        
		
		a.close();
        
		cout <<endl;
		cout << "\n\nfile read complete!\n";
		cin >> close;

        return 0;
    }


does anyone know what the deal is?

Reply With Quote
  #2  
Old February 27th, 2005, 04:37 PM
AsymptoticCoder AsymptoticCoder is offline
Information and Data Junkie
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Southern California, USA
Posts: 112 AsymptoticCoder User rank is Private First Class (20 - 50 Reputation Level)AsymptoticCoder User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 18 h 31 m 36 sec
Reputation Power: 10
Facebook
I believe you need to swap your parameters in the getline function.

getline(char * where to store data, what you are reading from);

Also, I think you need to store the data in a char *, not a string.

Reply With Quote
  #3  
Old February 27th, 2005, 04:57 PM
DaWei_M's Avatar
DaWei_M DaWei_M is offline
Renaissance Redneck
Dev Shed God 8th Plane (8500 - 8999 posts)
 
Join Date: Jan 2004
Location: Central New York. Texan via Arizona, out of his element!
Posts: 8,511 DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level) 
Time spent in forums: 4 Weeks 18 h 26 m 26 sec
Warnings Level: 20
Number of bans: 3
Reputation Power: 3268
You can read the data into a string. There is more than one 'getline.' I recommend the string class overloaded one for strings. Refer to your documentation for correct usage. I would suggest that advising your user to make sure he/she names the correct file is no substitute for checking the open operation to ensure it succeeded prior to making an attempt to read it. I would also suggest you condition your while test on a.good () as more things can happen than just end of file. Along those lines, one needs to think THOROUGHLY about WHEN eof might occur. It may occur during a gathering of data or it may occur prior to the gathering of any data. Disposition of one's storage area is at stake -- a lot of people wind up using the same datum twice or fail to properly use it once.
__________________
Functionality rules and clarity matters; if you can work a little elegance in there, you're stylin'.
If you can't spell "u", "ur", and "ne1", why would I hire you? 300 baud modem? Forget I mentioned it.
DaWei on Pointers Politically Incorrect.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > getline argument error

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap