Go Back   Forums > Community Chatterbox > Tech Corner > Programming
Memberlist Forum Rules Today's Posts
Search Forums:
Click here to use Advanced Search

Reply
 
Thread Tools Display Modes
Old 28-04-2005, 05:27 PM   #1
Kon-Tiki
[BANNED]

 
Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
Default

I'm refreshing my C/C++ skills and have encountered something that's stumped me. Dunno why it does this...
I open a .txt file I made with MsDos Editor in my program and use cout to show it. Instead of showing all the text in there, it shows a hex string (0x77fd44). Anybody know why this is?
Kon-Tiki is offline                         Send a private message to Kon-Tiki
Reply With Quote
Old 28-04-2005, 05:46 PM   #2
Kon-Tiki
[BANNED]

 
Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
Default

It's starting to come back to me... am fixing it now :bye:
Kon-Tiki is offline                         Send a private message to Kon-Tiki
Reply With Quote
Old 28-04-2005, 05:53 PM   #3
Data
retired
 
Data's Avatar


 
Join Date: Jun 2004
Location: Jan Mayen, Svalbard and Jan Mayen
Posts: 2,167
Default

you are outputting the fileobject to cout instead of it's contents.
__________________
Flowing with the stream of life
Data is offline                         Send a private message to Data
Reply With Quote
Old 28-04-2005, 06:01 PM   #4
Data
retired
 
Data's Avatar


 
Join Date: Jun 2004
Location: Jan Mayen, Svalbard and Jan Mayen
Posts: 2,167
Default

try this:

Code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main()
{
 *cout<<"Which file do you want to open?" << endl;
 *string name;
 *cin >> name;
 *cout << "Opening "<< name << "..." << endl;
 *ifstream file (name.c_str());
 *cout << file.rdbuf();
 *cin.get();
 *return 0;
}
__________________
Flowing with the stream of life
Data is offline                         Send a private message to Data
Reply With Quote
Old 28-04-2005, 06:02 PM   #5
Kon-Tiki
[BANNED]

 
Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
Default

Yup, noticed. I added a do-while loop that takes a line, puts it in a string and couts that, and that till the line's "". Might be buggy when the text looks like this:

Code:
Hello,

My name is Bob.

I like cheese.
Kon-Tiki is offline                         Send a private message to Kon-Tiki
Reply With Quote
Old 28-04-2005, 06:07 PM   #6
Data
retired
 
Data's Avatar


 
Join Date: Jun 2004
Location: Jan Mayen, Svalbard and Jan Mayen
Posts: 2,167
Default

with file exists check:

Code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main()
{
 *cout<<"Which file do you want to open?" << endl;
 *string name;
 *cin >> name;
 *cout << "Opening "<< name << "..." << endl;
 *ifstream file (name.c_str());
 *if(!file) {
 * * cout <<"file: "<< name << " doesn't exist" <<endl;
 * * return 1;
 *}

 *cout << file.rdbuf();
 *cin.get();
 *return 0;
}
__________________
Flowing with the stream of life
Data is offline                         Send a private message to Data
Reply With Quote
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
A Problem With Corrupted File kamiko Tech Corner 8 01-06-2007 08:34 PM
Need Help With Jar File Ioncannon Programming 4 22-03-2007 05:25 AM
Problem Running Some Dos Games In Xp (.pif File Problems) Jeff The Ninja Troubleshooting 6 20-02-2007 04:11 AM
Where Is The Exe. File. oyjah Troubleshooting 2 18-06-2006 10:54 PM
Pif File Guest Troubleshooting 8 28-04-2005 09:08 PM


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
Forum Jump
 


The current time is 04:44 PM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.