<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
Here's a youtube link to explain myself on what errors I'm getting.
我不明白为什么&#34; fstream&#34;对象无法正常工作。我声明它,然后我尝试用参数中的完整路径目录打开文件。 https://www.youtube.com/watch?v=mNm_OwVLR5g
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, char * argv[]) {
ifstream myfile;
ofstream pot
pot.open("accept.txt");
char status, answer;
string fname, lname, phone, address;
float rate;
myfile.open("/Users/Lois/Documents/Xcode/lab_6/potentials.txt");
myfile >> status;
myfile >> fname;
myfile >> lname;
myfile >> phone;
if (status == 'x' || status == 'X') {
rate = 7.9;
}
else {
rate = 12.9;
}
cout << "Name: " << lname << ", " << fname << endl;
cout << "Phone: " << phone << "\nRate: " << rate << endl;
cout << "Did the Customer accept the card offer?\nEnter 'A' for Yes or 'D' for No.\n";
cin >> answer;
cin.ignore();
if (answer == 'A' || answer == 'a') {
cout << "Enter Customers Address: \n";
getline(cin, address);
cout << "Thank you for taking the time to listen to and accept our offer! \n";
}
else if (answer == 'D' || answer == 'd') {
if (rate = 7.9) {
cout << "Are you certain? We offer cash back rewards.\n";
cout << "I can give you a special number to call for a better card. \n";
}
else
cout << "Thank you for your time today " << fname << "." << endl;
}
else
cout << "Please enter an appropriate response. \n";
pot << status;
pot << " ";
pot << fname;
pot << " ";
pot << lname;
pot << " ";
pot << address;
pot << endl;
pot.close();
cout << rate << endl;
return 0;
}
答案 0 :(得分:0)
I'm posting this answer for those who might one day come across the same problem I did.
The error was not with the code, other than the missing ";" which user657267 pointed out.
在CS50
上咨询另一个社区Facebook
后,我发现在终端窗口中使用clang
进行编译时,程序编译并运行无错误。我试着仔细阅读堆栈溢出的Q&amp; A,查看发布好问题的指南,以及help center
关于询问的问题。在那里,我发现允许的主题包括程序员常用的software tools
。
在这种情况下,我发现Xcode对我来说是 buggy 。我不确定是什么类型的bug。但Facebook集团对二元等的讨论远远超出了我的想法。
我现在要问另一个问题....
我不喜欢绝对的说话,但是每个人都会这样说
IDE 集成开发者环境(面向未来的googlers)
几年后,我在职业生涯中遇到过马车?最好的方法是避免遇到这样的错误,这会给我几小时的BS来从命令行编写代码吗?如果这是一个意见或主观问题,我很抱歉,但有什么其他方式可以提出这个问题。我正在学习如何编写程序,并且我花费时间的最突出的方法之一就是我遇到的调试问题,因为我的IDE编程方式。编译器如何写二进制文件,IDE默认保存它所写的文件等等。