my C++ code:
#include %26lt;windows.h%26gt;
#include %26lt;iostream%26gt;
#include %26lt;fstream%26gt;
using namespace std;
int main()
{
char a[128]="**** the truth!";
cout%26lt;%26lt;a%26lt;%26lt;endl;
ofstream outfile("temp.txt",ios::out);
for(int i=0;i%26lt;=127;i++)
{if(a[i]!=NULL)outfile%26lt;%26lt;a[i];}
outfile.close();
char b[128];
ifstream infile("temp.txt",ios::in);
for(int j=0;j%26lt;=127;j++)
{infile%26gt;%26gt;b[i];}
cout%26lt;%26lt;b%26lt;%26lt;endl;
infile.close();
return 0;
}
result:
**** the truth!
烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫!烫烫...
烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫蘁
[C++] Why the result of my programme is "烫烫烫烫烫烫烫烫"?
Probably because of this code
for(int j=0;j%26lt;=127;j++)
{infile%26gt;%26gt;b[i];}
Your for loop increments j but in the loop you are using b[i].
i should have a value of 127 or rubbish if it is out of scope.
radiata
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment