我已经告诉别人,编写using namespace std;代码是错误的,我应该用std::cout和std::cin直接代替.
为什么被using namespace std;认为是不好的做法?是低效还是冒着声明模糊变量(与名称std空间中的函数具有相同名称的变量)的风险?它会影响性能吗?
"一个人应该总是使用std :: string而不是c风格的字符串(char *)"这是几乎所有在这里发布的源代码的建议.虽然建议无疑是好的,但正在解决的实际问题不允许详细阐述原因?建议的方面详细.这个问题是作为占位符.
一个好的答案应该包括以下几个方面(详细):
std::string在C++中使用c风格的字符串?#1?#1是一个好的做法的情况是什么?我在第60行的任务中遇到了题目问题.请任何人尽快帮助我.
59 void storeFile();
60 {
61 cout<< "All the data members are stored in file." << endl;
62
63 ofstream outFile;
64 const char *outputFileName = ("record.txt");
65 outFile.open(outputFileName, ios::out);
66
67 if(!outFile)
68 {
69 cout<< "\nUnable to open the file." << outputFileName << endl;
70 }
71
72 else
73 {
74 outFile VUID; endl;
75 outFile campusID; endl;
76 outFile studentName; endl;
77 outFile fatherName; endl;
78 }
79 };
Run Code Online (Sandbox Code Playgroud)
错误:在第60行的'{'标记c ++之前预期的unqualified-id