相关疑难解决方法(0)

为什么"使用命名空间std"被认为是不好的做法?

我已经告诉别人,编写using namespace std;代码是错误的,我应该用std::coutstd::cin直接代替.

为什么被using namespace std;认为是不好的做法?是低效还是冒着声明模糊变量(与名称std空间中的函数具有相同名称的变量)的风险?它会影响性能吗?

c++ namespaces using-directives std c++-faq

2486
推荐指数
36
解决办法
78万
查看次数

为什么在C++中使用std :: string而不是c风格的字符串?

"一个人应该总是使用std :: string而不是c风格的字符串(char *)"这是几乎所有在这里发布的源代码的建议.虽然建议无疑是好的,但正在解决的实际问题不允许详细阐述原因?建议的方面详细.这个问题是作为占位符.

一个好的答案应该包括以下几个方面(详细):

  1. 为什么要std::string在C++中使用c风格的字符串?
  2. 提到的做法有哪些缺点(如果有的话)#1
  3. 在提到的建议的反面#1是一个好的做法的情况是什么?

c++ string c-strings

11
推荐指数
1
解决办法
6145
查看次数

在'{'标记c ++之前预期的unqualified-id

我在第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

c++

-1
推荐指数
1
解决办法
5万
查看次数

标签 统计

c++ ×3

c++-faq ×1

c-strings ×1

namespaces ×1

std ×1

string ×1

using-directives ×1