|
-
May 16th, 2001, 01:56 PM
#1
Thread Starter
Frenzied Member
Files...
I'm using the following code to read in data to a file.
When I read out the file, the data is being outputed underneath each other like this:
1
2
3
I want to read it out like this:
1 2 3
This is my code:
Code:
#include <iostream.h>
#include <fstream.h>
void main(){
ofstream OutFile("test.txt");
OutFile << "Hello world!";
OutFile.close();
OutFile.open("numbers.txt");
OutFile << 15 << " " << 42 << " " << 1;
OutFile.close();
ifstream InFile;
InFile.open("test.txt");
char p[50];
InFile >> p;
cout << p << endl;
InFile >> p;
cout << p << endl;
InFile.close();
int TempNum;
InFile.open("numbers.txt");
while (!InFile.eof()) {
InFile >> TempNum;
if (!InFile.eof())
cout<< TempNum << endl;
}
InFile.close();
InFile.open("test.txt");
while (!InFile.eof()) {
InFile >> p;
cout << p << endl;
}
}
-
May 16th, 2001, 03:46 PM
#2
Hyperactive Member
Remove the endl from the cout lines and see what happens.
Matt 
-
May 16th, 2001, 04:10 PM
#3
Banned
Instead of endl, you'll need ' ' (a space)
-
May 16th, 2001, 04:56 PM
#4
PowerPoster
like this maybe:
Code:
cout<<val1<<" "<<val2<<" "<<val3<<endl;
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
May 16th, 2001, 07:51 PM
#5
Frenzied Member
Err.... surely that's not what you meant, that's far too obvious... *confused*
Harry.
"From one thing, know ten thousand things."
-
May 16th, 2001, 08:04 PM
#6
PowerPoster
Yes, i know...I should be asking those questions, not answering them! heheh
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
May 16th, 2001, 08:37 PM
#7
Frenzied Member
Hmm maybe he should spend more time debugging simple errors and less time posting questions Takes 2 mins to find the error, or you can wait a few hours for an answer.
Harry.
"From one thing, know ten thousand things."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|