Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > HELP!

Reply
Thread Tools

HELP!

 
 
MC felon
Guest
Posts: n/a
 
      12-09-2006
I got myself dev c++. i tried (and for the first time) using 'std::'
for everything like cin, cout, getline etc.
it doesnt work! this program gave me 7 errors!!!!!!!
(dont mind conio2.h, it's the extra conio that handles many old
functions)
#include <iostream.h>
#include <conio2.h>
int main()
{
std::string str;
getline(std::cin,str,'\r');
std::cout<<"hi...\n\n";
std::cout<<str;
getch();
}

 
Reply With Quote
 
 
 
 
Salt_Peter
Guest
Posts: n/a
 
      12-09-2006

MC felon wrote:
> I got myself dev c++. i tried (and for the first time) using 'std::'
> for everything like cin, cout, getline etc.
> it doesnt work! this program gave me 7 errors!!!!!!!
> (dont mind conio2.h, it's the extra conio that handles many old
> functions)
> #include <iostream.h>


#include <iostream>
#include <string>

> #include <conio2.h>
> int main()
> {
> std::string str;
> getline(std::cin,str,'\r');
> std::cout<<"hi...\n\n";
> std::cout<<str;
> getch();
> }


In headers, you definitely want to use std:: and in source files, you
can do as follows:

#include <iostream>
#include <ostream>
#include <string>

int main()
{
using std::string;
using std::cout;
using std::endl;

string s_line(10, '-');
cout << s_line << endl;
}

 
Reply With Quote
 
 
 
 
MC felon
Guest
Posts: n/a
 
      12-09-2006
thanks

 
Reply With Quote
 
MC felon
Guest
Posts: n/a
 
      12-09-2006

#include <iostream>
#include <string>
#include <conio2.h>
int main()
{
using std::string;
using std::cout;
string str;
getline(std::cin,str,'\r');
cout<<str;
getch();
}
i tried this.Its supposed to print the content of the string when i
press enter, right? it's not.

 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      12-09-2006
"MC felon" <> wrote in message
news: ups.com...
>
> #include <iostream>
> #include <string>
> #include <conio2.h>
> int main()
> {
> using std::string;
> using std::cout;
> string str;
> getline(std::cin,str,'\r');
> cout<<str;
> getch();
> }
> i tried this.Its supposed to print the content of the string when i
> press enter, right? it's not.


Yes, it should. Maybe for some reason you need to flush the buffer. Try:

cout << str << std::endl;
and see if you see the output then.
Of course you have to type things for it to display.


 
Reply With Quote
 
MC felon
Guest
Posts: n/a
 
      12-09-2006


> Yes, it should. Maybe for some reason you need to flush the buffer. Try:
>
> cout << str << std::endl;
> and see if you see the output then.
> Of course you have to type things for it to display.


i type in a string and press enter... no reaction by computer (except
that the blinker goes to the next line). What's happening?

 
Reply With Quote
 
rossum
Guest
Posts: n/a
 
      12-09-2006
On 8 Dec 2006 20:48:11 -0800, "MC felon" <> wrote:

>
>#include <iostream>
>#include <string>
>#include <conio2.h>
>int main()
>{
> using std::string;
> using std::cout;
> string str;
> getline(std::cin,str,'\r');

You may find that '\n' works better here.

> cout<<str;

Safer to add "<< std::endl" to ensure that the buffer is flushed.

> getch();
>}
> i tried this.Its supposed to print the content of the string when i
>press enter, right? it's not.


 
Reply With Quote
 
=?ISO-8859-1?Q?Erik_Wikstr=F6m?=
Guest
Posts: n/a
 
      12-09-2006
On 2006-12-09 11:27, MC felon wrote:
>
>> Yes, it should. Maybe for some reason you need to flush the buffer. Try:
>>
>> cout << str << std::endl;
>> and see if you see the output then.
>> Of course you have to type things for it to display.

>
> i type in a string and press enter... no reaction by computer (except
> that the blinker goes to the next line). What's happening?


Because you put the '\r' in there, either leave it out all together or
use '\n', unless you are reading/writing to a file in binary mode you'll
probably never have to use '\r'.

--
Erik Wikström
 
Reply With Quote
 
Gavin Deane
Guest
Posts: n/a
 
      12-09-2006

rossum wrote:
> On 8 Dec 2006 20:48:11 -0800, "MC felon" <> wrote:
> > getline(std::cin,str,'\r');

> You may find that '\n' works better here.


If you don't specify a terminating character at all, '\n' is the
default. So these are equivalent and you might consider the second one
simpler - it's certainly commonplace.

getline(std::cin,str,'\n');
getline(std::cin,str);

Gavin Deane

 
Reply With Quote
 
Howard
Guest
Posts: n/a
 
      12-12-2006

"MC felon" <> wrote in message
news: ups.com...
> thanks
>


You're welcome!

Now, how about quoting what you're replying to next time, eh?

-Howard


 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57