作者raytekimo (我的梦做太大)
看板MacDev
标题[问题] Xcode v.s. Visual Studio 2008
时间Wed Apr 1 23:11:03 2009
今天早上在学校用Visual Studio 2008 写程式
以下是code:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
char answer;
string first;
string middle;
string last;
string name;
string age;
char sex;
ofstream fout("output.txt");
fout << "Name" << setw(16) << "Age" << setw(8) << "Sex" << endl;
for(int i=0; i<3; i++)
{
cout << "Does the employee have middle name (Y/N)?" ;
cin >> answer ;
cout << "Input the emplyee's name, age, and sex (M/F): " ;
if (answer=='Y')
{
cin >> first >> middle >> last >> age >> sex;
name = first + ", " + middle + " " + last;
fout << name << setw(20-name.length()) << age
<< setw(10-age.length()) << sex << endl;
}
if (answer=='N')
{
cin >> first >> last >> age >> sex;
name = first + ", " + last;
fout << name << setw(20-name.length()) << age
<< setw(10-age.length()) << sex << endl;
}
}
return 0;
}
发现一件很奇怪的事情...
我早上用这个code可以轻易做到助教的要求,
但回到家,发现!!!
code里面说要输入三个name, age, sex 之後
output.txt档才会完整...
在学校跑都ok
但是在家里跑却...(在终端机跑过专案了,也确实打过那些资料)
只fout了「fout << "Name" << setw(16) << "Age" << setw(8) << "Sex" << endl;」
这段code的东西。
我後来cin的资料都没有显示在output.txt档中...
不知道该如何处理?
不行的话...我就要在paralel(不确定拼法对不对啦)灌个VS2008来取代Xcode了...
虽然我觉得Xcode漂亮多了!!
感谢大大~
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.135.160.31
1F:推 ducksteven:开 Xcode 的 debugger 吧! 04/01 23:15
2F:推 appleway:你没有关档。 04/02 00:21
3F:→ raytekimo:想请问一下debugger的用意是什麽?关档是关终端机还是? 04/02 22:07
4F:→ raytekimo:谢谢 04/02 22:07
5F:推 appleway:你的code里面只有开档没有close file 04/03 01:16
6F:→ appleway:fout 有可能都先放在buffer 关档的时候一口气写进去 04/03 01:16
7F:→ raytekimo: 喔喔我大概了解了!应该是说fout.close()吧!谢谢~ 04/03 23:16