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 July 31st, 2009, 05:54 PM
nathanpc's Avatar
nathanpc nathanpc is offline
PixHost.tk Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Location: Brazil
Posts: 58 nathanpc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 25 m 29 sec
Reputation Power: 0
Send a message via ICQ to nathanpc Send a message via AIM to nathanpc Send a message via MSN to nathanpc Send a message via Yahoo to nathanpc Send a message via Google Talk to nathanpc Send a message via Skype to nathanpc Send a message via XFire to nathanpc
Facebook Orkut
Exclamation Error in getline() Argument

Hello,
When i try to compile this simple example for learning i have some errors while compiling:
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
    char temp[100];
    ifstream file("test.txt");
    string linha = getline(temp, 100, file);
    if(linha == "teste")
      {
         cout << "Hello, World";
      }
}


And here is the log of g++:
Code:
ubuntu@ubuntu-laptop:~/Desktop$ g++ -o test test.cpp
test.cpp: In function ‘int main()’:
test.cpp:10: error: cannot convert ‘char*’ to ‘char**’ for argument ‘1’ to ‘__ssize_t getline(char**, size_t*, FILE*)’
ubuntu@ubuntu-laptop:~/Desktop$ 


What is wrong?

Thanks,
Nathan Paulino Campos

Reply With Quote
  #2  
Old July 31st, 2009, 06:03 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,387 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 1 Day 21 h 39 m 3 sec
Reputation Power: 4080
Your problem is around where you're using getline(). You should never have to use a char buf, when you have C++ and a string object.

Simply do this instead.
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
    ifstream file("test.txt");
    string linha;
    getline(file, linha);
    if(linha == "teste")
      {
         cout << "Hello, World";
      }
    return 0;
}
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Reply With Quote
  #3  
Old July 31st, 2009, 06:24 PM
nathanpc's Avatar
nathanpc nathanpc is offline
PixHost.tk Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Location: Brazil
Posts: 58 nathanpc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 25 m 29 sec
Reputation Power: 0
Send a message via ICQ to nathanpc Send a message via AIM to nathanpc Send a message via MSN to nathanpc Send a message via Yahoo to nathanpc Send a message via Google Talk to nathanpc Send a message via Skype to nathanpc Send a message via XFire to nathanpc
Facebook Orkut
Thanks very much!!!!!!!!!!!!!

Reply With Quote
  #4  
Old July 31st, 2009, 06:31 PM
nathanpc's Avatar
nathanpc nathanpc is offline
PixHost.tk Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Location: Brazil
Posts: 58 nathanpc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 25 m 29 sec
Reputation Power: 0
Send a message via ICQ to nathanpc Send a message via AIM to nathanpc Send a message via MSN to nathanpc Send a message via Yahoo to nathanpc Send a message via Google Talk to nathanpc Send a message via Skype to nathanpc Send a message via XFire to nathanpc
Facebook Orkut
But how i can do if my file is like this:
Code:
teste
hello

And i want to show the two, the one like in your post and the second like this:
Code:
    if(linha == "arquivo")
      {
         cout << "Testing...\n";
      }


How i can do this??????????

Last edited by nathanpc : July 31st, 2009 at 06:34 PM. Reason: put the code

Reply With Quote
  #5  
Old July 31st, 2009, 07:18 PM
sizablegrin's Avatar
sizablegrin sizablegrin is offline
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Jun 2005
Posts: 5,964 sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 2 Days 12 h 47 m 19 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 4850
If you want to get two lines I suppose you could use "getline" twice. Stuff like that.
__________________
Write no code whose complexity leaves you wondering what the hell you did.
Politically Incorrect DaWei on Pointers Grumpy on Exceptions

Reply With Quote
  #6  
Old July 31st, 2009, 07:24 PM
nathanpc's Avatar
nathanpc nathanpc is offline
PixHost.tk Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Location: Brazil
Posts: 58 nathanpc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 25 m 29 sec
Reputation Power: 0
Send a message via ICQ to nathanpc Send a message via AIM to nathanpc Send a message via MSN to nathanpc Send a message via Yahoo to nathanpc Send a message via Google Talk to nathanpc Send a message via Skype to nathanpc Send a message via XFire to nathanpc
Facebook Orkut
Thanks, but i solved thid problem: http://www.dreamincode.net/forums/showtopic117882.htm
Comments on this post
sizablegrin disagrees: Great. Nothing like making us waste and duplicate effort without telling us.
holodoc agrees: Balance... You found help elsewhere and even gave the link to the solution... Its unfair to derep
you for that.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Error in getline() Argument

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