Output to monitor not the same as output to .txt file.

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 1251 Views - Last Post: 27 September 2009 - 05:58 PM Rate Topic: -----

#1 seeP+  Icon User is offline

  • D.I.C Addict

Reputation: 55
  • View blog
  • Posts: 601
  • Joined: 20-July 09

Output to monitor not the same as output to .txt file.

Posted 26 September 2009 - 06:07 PM

int main() 
{
	 stringstream out;
	 ofstream outFile;
	 outFile.open("ascii.txt");
	 string con = "";
	  char symbol = 128;
	 for(int x = 128; x < 267; x++)
	  {
			 outFile<<x<<"= "<<symbol++<<endl;
			  cout<<x<<"= "<<symbol++<<endl;
	  }
	  outFile.close();

system("pause");
return 0;
}


Can anyone explain why the output in the command line window is different from the .txt file.
I am getting:
128 = // in command prompt
128 = // in text file
129 = //in command prompt
129 = ,//in text file
131 = //int command prompt
131 = //in text file

Is This A Good Question/Topic? 0
  • +

Replies To: Output to monitor not the same as output to .txt file.

#2 ericr2427  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 38
  • View blog
  • Posts: 376
  • Joined: 01-December 08

Re: Output to monitor not the same as output to .txt file.

Posted 26 September 2009 - 06:13 PM

You're doing symbol++ for both outputs, so symbol is really being incremented by 2 each time. Here's how it should be:
			 outFile<<x<<"= "<<symbol++<<endl;
			  cout<<x<<"= "<<symbol<<endl;


Was This Post Helpful? 0
  • +
  • -

#3 seeP+  Icon User is offline

  • D.I.C Addict

Reputation: 55
  • View blog
  • Posts: 601
  • Joined: 20-July 09

Re: Output to monitor not the same as output to .txt file.

Posted 26 September 2009 - 06:16 PM

That does not change the outcome.
Was This Post Helpful? 0
  • +
  • -

#4 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Output to monitor not the same as output to .txt file.

Posted 26 September 2009 - 07:10 PM

What are you talking about?
Was This Post Helpful? 0
  • +
  • -

#5 seeP+  Icon User is offline

  • D.I.C Addict

Reputation: 55
  • View blog
  • Posts: 601
  • Joined: 20-July 09

Re: Output to monitor not the same as output to .txt file.

Posted 26 September 2009 - 07:35 PM

Copy and paste then run the code. Look at the output screen and the .txt file.
Was This Post Helpful? 0
  • +
  • -

#6 poncho4all  Icon User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,405
  • Joined: 15-July 09

Re: Output to monitor not the same as output to .txt file.

Posted 26 September 2009 - 08:49 PM

I think he might be right. If you think about it the c++ after the variable means that the variable is gonna change on its next appearance.
Maybe what he needs is either ++c with the ++before the variable like this.
		outFile<<x<<"= "<<++symbol<<endl;
			  cout<<x<<"= "<<symbol<<endl;


Or
		outFile<<x<<"= "<<symbol<<endl;
			  cout<<x<<"= "<<symbol++<<endl;



Hope that helps.
Was This Post Helpful? 0
  • +
  • -

#7 seeP+  Icon User is offline

  • D.I.C Addict

Reputation: 55
  • View blog
  • Posts: 601
  • Joined: 20-July 09

Re: Output to monitor not the same as output to .txt file.

Posted 26 September 2009 - 08:57 PM

Thank you for the response. I have made every change suggested. It does not change the outcome. If you copy and paste the code you will see that the display is different from what is being stored in the file.

#include <iostream>
#include <sstream>
#include <fstream>
using namespace std;

int main() 
{
	 stringstream out;
	 ofstream outFile;
	 outFile.open("ascii.txt");
	 string con = "";
	  char symbol = 128;
	  int x = 128;
	
			 outFile<<x<<"= "<<symbol<<endl;
			  cout<<x<<"= "<<symbol<<endl;
	
	  outFile.close();
	 

system("pause");
return 0;
}


Here is a easier code to read. After copying, pasting, and running it, look at the displayed character. Open the created text file from the program. They are different.

This post has been edited by seeP+: 26 September 2009 - 09:03 PM

Was This Post Helpful? 0
  • +
  • -

#8 poncho4all  Icon User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,405
  • Joined: 15-July 09

Re: Output to monitor not the same as output to .txt file.

Posted 26 September 2009 - 09:09 PM

Well you are trying to go throw some elements that cant be printed thats why the program makes a bip sound and everything goes mad.
I tried it this way and it works :P
#include <iostream>
#include <fstream>

using namespace std;
int main()
{
	 //stringstream out;
	 ofstream outFile;
	 outFile.open("ascii.txt");
	 //string con = "";
	 char symbol = (char)54;
	 for(int x = 54; x < 99; x++)
	  {
			 outFile<<x<<"= "<<symbol<<endl;
			  cout<<x<<"= "<<symbol++<<endl;
	  }
	  outFile.close();

system("pause");
return 0;
}


Hope that helps ;)
Was This Post Helpful? 0
  • +
  • -

#9 seeP+  Icon User is offline

  • D.I.C Addict

Reputation: 55
  • View blog
  • Posts: 601
  • Joined: 20-July 09

Re: Output to monitor not the same as output to .txt file.

Posted 26 September 2009 - 09:14 PM

I am sorry poncho and others who replied. I should have clarified more. Lol. Ok, I see your code poncho. Thank you. Everything in my file is correct untill 128 and above. Have you copied and pasted my latest code?

32 through 127 is fine.

This post has been edited by seeP+: 26 September 2009 - 09:23 PM

Was This Post Helpful? 0
  • +
  • -

#10 poncho4all  Icon User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,405
  • Joined: 15-July 09

Re: Output to monitor not the same as output to .txt file.

Posted 26 September 2009 - 10:04 PM

Wow.... :(

Well ascii is a 7-bit and the "Extended ascii" is 8-bit so as far as i know it still has some very weird bugs, one of wich you just met. I cant explain why this happends but i can redirect you to the other "Extended ASCII" table wich as you will see is exactly as it appears in the text ;)

http://www.petefreit...ts/ascii-codes/
Was This Post Helpful? 0
  • +
  • -

#11 seeP+  Icon User is offline

  • D.I.C Addict

Reputation: 55
  • View blog
  • Posts: 601
  • Joined: 20-July 09

Re: Output to monitor not the same as output to .txt file.

Posted 26 September 2009 - 10:16 PM

Thanks for the help poncho. The link is similar to what I have created with my original post. Since extended ascii is 8-bit would it be the compilers fault for not displaying the correct output?
Was This Post Helpful? 0
  • +
  • -

#12 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6052
  • View blog
  • Posts: 23,487
  • Joined: 23-August 08

Re: Output to monitor not the same as output to .txt file.

Posted 26 September 2009 - 11:55 PM

Remember, your text file is represented by 1 and 0 on the disk. It's up to the application how it's going to display those 1s and 0s.

Therefore, it's all about character encoding and the code pages. Your text file, apparently running on Windows, is being displayed using the Windows-1252 code page, which represents the extended ASCII code 128 as the Euro symbol; the terminal, using IBM code page 437, represents code 129 as the umlauted-u.
Was This Post Helpful? 0
  • +
  • -

#13 seeP+  Icon User is offline

  • D.I.C Addict

Reputation: 55
  • View blog
  • Posts: 601
  • Joined: 20-July 09

Re: Output to monitor not the same as output to .txt file.

Posted 27 September 2009 - 10:13 AM

View PostseeP+, on 26 Sep, 2009 - 05:07 PM, said:

int main() 
{
	 stringstream out;
	 ofstream outFile;
	 outFile.open("ascii.txt");
	 string con = "";
	  char symbol = 128;
	 for(int x = 128; x < 267; x++)
	  {
			 outFile<<x<<"= "<<symbol++<<endl;
			  cout<<x<<"= "<<symbol++<<endl;
	  }
	  outFile.close();

system("pause");
return 0;
}


Can anyone explain why the output in the command line window is different from the .txt file.
I am getting:
128 = // in command prompt
128 = // in text file
129 = //in command prompt
129 = ,//in text file
131 = //int command prompt
131 = //in text file



View PostJackOfAllTrades, on 26 Sep, 2009 - 10:55 PM, said:

Remember, your text file is represented by 1 and 0 on the disk. It's up to the application how it's going to display those 1s and 0s.

Therefore, it's all about character encoding and the code pages. Your text file, apparently running on Windows, is being displayed using the Windows-1252 code page, which represents the extended ASCII code 128 as the Euro symbol; the terminal, using IBM code page 437, represents code 129 as the umlauted-u.


Thank you for the links Jack. My text file is the same as the Windows link of ASCII. So the output to the file is correct, but why is the output in the command prompt window different?

Try to copy and run the code.

View PostseeP+, on 26 Sep, 2009 - 05:07 PM, said:

int main() 
{
	 stringstream out;
	 ofstream outFile;
	 outFile.open("ascii.txt");
	 string con = "";
	  char symbol = 128;
	 for(int x = 128; x < 267; x++)
	  {
			 outFile<<x<<"= "<<symbol++<<endl;
			  cout<<x<<"= "<<symbol++<<endl;
	  }
	  outFile.close();

system("pause");
return 0;
}


Can anyone explain why the output in the command line window is different from the .txt file.
I am getting:
128 = // in command prompt
128 = // in text file
129 = //in command prompt
129 = ,//in text file
131 = //int command prompt
131 = //in text file

Was This Post Helpful? 0
  • +
  • -

#14 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6052
  • View blog
  • Posts: 23,487
  • Joined: 23-August 08

Re: Output to monitor not the same as output to .txt file.

Posted 27 September 2009 - 10:31 AM

Because that's how you've written it, just as ericr said in the second post!

for(int x = 128; x < 267; x++)
{
    // First time through, symbol == 128
    // This line prints the symbol for 128, then increments symbol.
    outFile<<x<<"= "<<symbol++<<endl;

    // First time through, symbol is now 129 (because you incremented it in the line above!
    cout<<x<<"= "<<symbol++<<endl;
    
    // Now symbol has been incremented AGAIN, and is 130.
}


Was This Post Helpful? 0
  • +
  • -

#15 seeP+  Icon User is offline

  • D.I.C Addict

Reputation: 55
  • View blog
  • Posts: 601
  • Joined: 20-July 09

Re: Output to monitor not the same as output to .txt file.

Posted 27 September 2009 - 03:13 PM

View Postponcho4all, on 26 Sep, 2009 - 09:04 PM, said:

Wow.... :(

Well ascii is a 7-bit and the "Extended ascii" is 8-bit so as far as i know it still has some very weird bugs, one of wich you just met. I cant explain why this happends but i can redirect you to the other "Extended ASCII" table wich as you will see is exactly as it appears in the text ;)

http://www.petefreit...ts/ascii-codes/

And after his post I said "it doesn't matter". If you did not bother to copy and run the code then you don't know what I am talking about. The output to the text is not the same as the output to the prompt even though they are the same ascii code!
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2