LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-14-2009, 10:51 PM   #1
steve2688
LQ Newbie
 
Registered: Jun 2009
Posts: 4

Rep: Reputation: 0
Unhappy Problem in read a text file and display in DOS command...


hello, i am (super) new in c++ and i have a problem in read a text file,to display the text in DOS command,for example i would like to display a text file information in

(C:\Documents and Settings\Steve\Desktop\Project\example.txt)

the content such like:

Lim, 11111, study
Alice, 22222, Exam
Raymond, 33333, sick
Rick, 44444, exercise

i knew this can be very easier to write q coding but i am too noob (mb). can anyone give me a help and your helpful will be so appreciated.

this is my example coding i take from web but also display nothing....


#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>

int main ()
{
char buffer[4];
ifstream examplefile ("example.txt");

if (! examplefile.is_open())
{
cout << "Error opening file";
exit (1);
}

while (! examplefile.eof() )
{
cout <<"hello";
examplefile.getline (buffer,3);
cout << buffer << endl;
}
return 0;
}
 
Old 06-14-2009, 11:32 PM   #2
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
I'm not a C++ coder, so can not help you here. I did try to compile your code and got warnings on my Linux system.


There is a dedicated programming section here at LQ where your thread will fit better. You can ask a moderator to move your thread there by using the report button at the bottom of your post.
 
Old 06-14-2009, 11:41 PM   #3
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,627

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
steve2688 you do know this is a Linux forum and NOT an MS windows ( xp,vista,windows 7 beta) forum ???
to read a text doc
Code:
nano /path/to/the/file/FileName.txt
------- or ---------
vi /path/to/the/file/FileName.txt
 
Old 06-16-2009, 03:26 AM   #4
steve2688
LQ Newbie
 
Registered: Jun 2009
Posts: 4

Original Poster
Rep: Reputation: 0
opp....
sorry for all i did...
 
Old 06-16-2009, 03:30 AM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 06-16-2009, 03:35 AM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by steve2688 View Post
hello, i am (super) new in c++ and i have a problem in read a text file,to display the text in DOS command,for example i would like to display a text file information in
if you want to read files in DOS, use the type command (or just type "edit" on the command line. The "type" command is suitable to files if you want to automate. No need to use C++ !!
 
Old 06-16-2009, 02:47 PM   #7
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
@John VV and ghostdog74

I think steve2688 is trying to write a small program as an exercise.
 
Old 06-17-2009, 03:04 AM   #8
aspire1
Member
 
Registered: Dec 2008
Distribution: Ubuntu
Posts: 62

Rep: Reputation: 23
Haven't looked at C++ for a long, long time but anyhow:

Code:
#include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;

int main ()
{
         char buffer[50];
         ifstream examplefile ("example.txt");

         if (! examplefile.is_open())
          {
           cout << "Error opening file";
            exit (1);
           }

       while (! examplefile.eof() )
       {
          cout <<"hello";
          examplefile.getline (buffer,50);
          cout << buffer << endl;
       }
 
      return 0;
}
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Flip - Convert text file line endings between Unix and DOS formats LXer Syndicated Linux News 1 03-03-2009 01:38 PM
SED - display text on specific line of text file 3saul Linux - Software 3 12-29-2005 04:32 PM
mkisofs can't read existing DOS file. breany Linux - Software 2 01-29-2004 08:45 AM
converting text file from linux to ms dos Berhanie Linux - Newbie 4 12-24-2003 10:54 PM
Display/Read line 'N' in a text file using script ganninu Linux - Newbie 2 10-13-2003 05:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration