我已经告诉别人,编写using namespace std;代码是错误的,我应该用std::cout和std::cin直接代替.
为什么被using namespace std;认为是不好的做法?是低效还是冒着声明模糊变量(与名称std空间中的函数具有相同名称的变量)的风险?它会影响性能吗?
我正在构建一个以这种格式获取输入文件的程序:
title author
title author
etc
and outputs to screen
title (author)
title (author)
etc
Run Code Online (Sandbox Code Playgroud)
我目前遇到的问题是错误:
"ifstream infile的类型不完整,无法定义"
以下是该计划:
#include <iostream>
#include <string>
#include <ifstream>
using namespace std;
string bookTitle [14];
string bookAuthor [14];
int loadData (string pathname);
void showall (int counter);
int main ()
{
int counter;
string pathname;
cout<<"Input the name of the file to be accessed: ";
cin>>pathname;
loadData (pathname);
showall (counter);
}
int loadData (string pathname) // Loads data from infile into arrays
{
ifstream infile; …Run Code Online (Sandbox Code Playgroud)