473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

hi find the error and send me the correct running code. in the same piece of code

1
#include<iostream.h>
#include<conio.h>

void main()
{
char buffer[max];

clrscr();
ofstream out ("OUTPUT", ios::in|ios::out);

if(!out)
{
cerr<<"Open failed\n";
exit(1);
}
cout<<"Enter a line of data:";

while(cin.get (buffer, max) == eof())
{
put<<buffer <<endl;
cout<< "Next line: ";
}

getch();
}
Jun 20 '07 #1
4 1251
Meetee
931 Expert Mod 512MB
#include<iostream.h>
#include<conio.h>

void main()
{
char buffer[max];

clrscr();
ofstream out ("OUTPUT", ios::in|ios::out);

if(!out)
{
cerr<<"Open failed\n";
exit(1);
}
cout<<"Enter a line of data:";

while(cin.get (buffer, max) == eof())
{
put<<buffer <<endl;
cout<< "Next line: ";
}

getch();
}
Use code something like this

Expand|Select|Wrap|Line Numbers
  1. .#include<iostream.h>
  2. #include<fstream.h>
  3. //don't use conio.h in cpp file
  4.  
  5. int main() //new style programming has int as the type of main
  6. {
  7.         int max = 5; //define max
  8.         char buffer[max];
  9.  
  10. //      clrscr(); //don't use this also
  11.         ofstream out ("OUTPUT", ios::in|ios::out);
  12.  
  13.         if(!out)
  14.         {
  15.                 cerr<<"Open failed\n";
  16.                 exit(1);
  17.         }
  18.         cout<<"Enter a line of data:";
  19.  
  20.         while(cin.get (buffer, max) == eof())
  21.         {
  22.                 put<<buffer <<endl;
  23.                 cout<< "Next line: ";
  24.         }
  25.  
  26.        return 0;
  27. }
Hope this helps
Jun 20 '07 #2
archonmagnus
113 100+
You can use "conio.h", but it will only work for Windows/DOS prompts. It is generally not recommended, but it can work if used in the right context.

Also, if you are attempting to right the code in ANSI/ISO C++, then you should use "#include <iostream>" rather than "#include <iostream.h>"
Jun 20 '07 #3
This is working good:
Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. const MAXBUF = 256;
  7.  
  8. int _tmain(int argc, _TCHAR* argv[])
  9. {
  10.     char buffer[MAXBUF];
  11.  
  12.     ofstream out ("OUTPUT");
  13.  
  14.     if(!out)
  15.     {
  16.     cerr<<"Open failed\n";
  17.     exit(1);
  18.     }
  19.     cout<<"Enter a line of data:";
  20.  
  21.     while(cin.getline(buffer, MAXBUF-1))
  22.     {
  23.         if (!stricmp(buffer, "q")) {
  24.             break;
  25.         }
  26.  
  27.         out<<buffer <<endl;
  28.         cout<< "Next line: ";
  29.     }
  30.  
  31.  
  32.     return 0;
  33. }
  34.  
  35.  
Cheers

#include<iostream.h>
#include<conio.h>

void main()
{
char buffer[max];

clrscr();
ofstream out ("OUTPUT", ios::in|ios::out);

if(!out)
{
cerr<<"Open failed\n";
exit(1);
}
cout<<"Enter a line of data:";

while(cin.get (buffer, max) == eof())
{
put<<buffer <<endl;
cout<< "Next line: ";
}

getch();
}
Jun 20 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
Lotta errors here:
cout<<"Enter a line of data:";

while(cin.getline(buffer, MAXBUF-1))
{
if (!stricmp(buffer, "q")) {
break;
This is a _tmain. You can't use char literals or funcitons like stricmp. You need the TCHAR equivalents:

Expand|Select|Wrap|Line Numbers
  1. cout<<_T"Enter a line of data:";
  2.  
  3.     while(cin.getline(buffer, MAXBUF-1))
  4.     {
  5.         if (!_tstricmp(buffer, _T"q")) {
  6.             break;
  7.  
etc...

Otherwise, you can't switch between char and wchar_t. Even in the above code I don't know what the TCHAR equivalent is for cout. It has to toggle between cout and wcout.

If oyu can't use the TCHAR macros, you shoul sjust have a main() rather than a _tmain() so everyone knows the code is not UNICODE compliant.
Jun 20 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Fabrice Labrousse | last post by:
Hello, Here is a hard problem i cannot solve about window.opener method I think you'll need to be a specialist to find the solution... i can't find the solution by myself ! Please help me. Here...
2
by: Mal | last post by:
I think that I am having a problem with some code that doesn't stop running. When I enter a table I can't close it again - I recieve an error about "This action will reset in break mode".. ...
5
by: Bob Dydd | last post by:
Hi Everybody I have an Access 2000 MDB with the Usual FrontEnd/BackEnd Arrangement. The program depends on being able link to "Inbox" in Ms Outlook 2000. This is easy enough to do from the...
5
by: Martin Robins | last post by:
I have never dabbled with ASP.NET until now so be warned! I have created a web application with the single default form: WebForm1.aspx and when I try to display it I get this error. My...
9
by: B-Dog | last post by:
I've built a small app that sends mail through our ISP's SMTP server but when I try to send through my local exchange server I get CDO error. Does webmail use SMTP or does it strictly rely on...
18
by: William | last post by:
I have the following javascript function that updates a scroll_list and sends the updated entry (with its index) to a server script ( i.e. http://mkmxg00/cgi/confirmUpload.pl ) for further...
4
by: JoeC | last post by:
I am trying to write a program and I send a pointer to an object to another object and I want to get a number out of that object It is strange this works: static mapmgt m(b, trn, b->GetSizeX(),...
2
by: moondaddy | last post by:
I had to repost this because I had to update and change my msdn alias. I will re-ask the question and clarify a few things that were not clear before. This code is all executed on my dev...
3
by: Lance Wynn | last post by:
Hello, I am receiving this error when trying to instantiate a webservice component. I have 2 development machines, both are XP sp2 with VS 2008 installed. On one machine, the code works fine. On...
11
by: Jialiang Ge [MSFT] | last post by:
Hello Peter, I once came across the same error "ExecuteReader requires the command to have a transaction when the connection assigned? with running two threads talking with the database. There...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.