![]() |
#1 | ||
![]() ![]() ![]() Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
|
![]() 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? |
||
![]() ![]() |
|
![]() |
#2 | ||
![]() ![]() ![]() Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
|
![]() It's starting to come back to me... am fixing it now :bye:
|
||
![]() ![]() |
|
![]() |
#3 | ||
![]() ![]() ![]() ![]() ![]() Join Date: Jun 2004
Location: Jan Mayen, Svalbard and Jan Mayen
Posts: 2,167
|
![]() you are outputting the fileobject to cout instead of it's contents.
__________________
Flowing with the stream of life |
||
![]() ![]() |
|
![]() |
#4 | ||
![]() ![]() ![]() ![]() ![]() Join Date: Jun 2004
Location: Jan Mayen, Svalbard and Jan Mayen
Posts: 2,167
|
![]() 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 |
||
![]() ![]() |
|
![]() |
#5 | ||
![]() ![]() ![]() Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
|
![]() 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. |
||
![]() ![]() |
|
![]() |
#6 | ||
![]() ![]() ![]() ![]() ![]() Join Date: Jun 2004
Location: Jan Mayen, Svalbard and Jan Mayen
Posts: 2,167
|
![]() 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 |
||
![]() ![]() |
|
![]() |
|
![]() |
||||
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 |
|
|
||
  |