![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
getline() while including <string.h>
Hello...
i tried to use this code: #include <iostream.h>
#include <string.h>
int main()
{
std::string quote;
std::cin.getline(quote,50);
if(quote=="The one and the only one...darkone.")
std::cout<<"\a";
}getline() gives these errors: C:\C++\C++.cpp In function `int main()': 6 C:\C++\C++.cpp no matching function for call to `std::basic_istream<char, std::char_traits<char> >::getline(std::string&, int)' note C:\Dev-Cpp\include\c++\3.4.2\bits\istream.tcc:582 candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::getline(_CharT*, std::streamsize, _CharT) [with _CharT = char, _Traits = std::char_traits<char>] note C:\Dev-Cpp\include\c++\3.4.2\bits\istream.tcc:582 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::getline(_CharT*, std::streamsize) [with _CharT = char, _Traits = std::char_traits<char>] In the other hand getline() works well with a variable decleared as char. thank you 4 helping. ![]()
__________________
From the bottom of the stone steps... ...i'm calling still. |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4
![]() |
#include <iostream>
#include <string>
int main()
{
std::string quote;
std::cin >> quote;
if(quote=="The one and the only one...darkone.")
std::cout<<"\a";
}
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand." - B. Russell http://web.bryant.edu/~srk2 |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: May 2005
Location: Indiana
Posts: 130
Rep Power: 4
![]() |
If your heart is set on the getline(), then you should check it's prototype depending on library: either this or this .
Last edited by EverLearning; Jul 30th, 2005 at 2:12 PM. Reason: note on libraries |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
|
Thank you for helping... but using this code will take only the characters before the first space.
e.g. if i typed in :"The one and the only one...darkone." it will only take the "the". thanx again.
__________________
From the bottom of the stone steps... ...i'm calling still. |
|
|
|
|
|
#5 |
|
Programmer
Join Date: Jun 2005
Posts: 99
Rep Power: 4
![]() |
skuinders that will only read in one word not what darkone916 wanted.
@ darkone916 in <string> there's a more useful getline function, that you dont have to specify the length of the input: #include <iostream>
#include <string>
int main()
{
std::string quote;
std::getline( std::cin, quote );
if(quote=="The one and the only one...darkone.")
std::cout<<"\a";
}This will read in the input up to a '\n'. |
|
|
|
|
|
#6 |
|
Hobbyist Programmer
|
Yep!!! it works!!!
thanx everyone!!! ![]() ![]() ![]() ![]() ![]() ![]()
__________________
From the bottom of the stone steps... ...i'm calling still. |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Jul 2005
Posts: 3
Rep Power: 0
![]() |
Nice job.. i making aprograms app of my own Very easy.. and debugg mod
![]() |
|
|
|
|
|
#8 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
Darkone, just a note, you can use "using namespace std;" instead of "std::bla" like his:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string quote;
getline(cin, quote );
if(quote=="The one and the only one...darkone.")
cout<<"\a";
} |
|
|
|
|
|
#9 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4
![]() |
woops sorry... I forgot about that :o
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand." - B. Russell http://web.bryant.edu/~srk2 |
|
|
|
|
|
#10 | |
|
Hobbyist Programmer
|
Quote:
![]()
__________________
From the bottom of the stone steps... ...i'm calling still. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|