相关疑难解决方法(0)

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

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

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

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

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

Infile不完整类型错误

我正在构建一个以这种格式获取输入文件的程序:

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)

c++ arrays file-io function

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

c++ ×2

arrays ×1

c++-faq ×1

file-io ×1

function ×1

namespaces ×1

std ×1

using-directives ×1