如何在VC++6.0上解决这个问题
How can i solve this on VC++ 6.0
我有这个简单的代码,但我不知道这个的错误在哪里
#include <iostream.h>
#include <fstream.h>
#include <string.h>
using namespace std;
int main(){
string s;
cout<<"Entrer nom de fichier avec le source";
cin s;
ifstream fout;
fout.open(s);
s=fout.getche();
fout.close();
cout<<s;
return 0;
}
导致编译后显示的错误是:
d:workespace3.cpp(5) : error C2871: 'std' : does not exist or is not a namespace
d:workespace3.cpp(8) : error C2653: 'std' : is not a class or namespace name
d:workespace3.cpp(8) : error C2065: 'string' : undeclared identifier
d:workespace3.cpp(8) : error C2146: syntax error : missing ';' before identifier 's'
d:workespace3.cpp(8) : error C2065: 's' : undeclared identifier
d:workespace3.cpp(10) : error C2146: syntax error : missing ';' before identifier 's'
d:workespace3.cpp(13) : error C2039: 'getche' : is not a member of 'ifstream'
c:program files (x86)microsoft visual studiovc98includefstream.h(98) : see declaration of 'ifstream'
Error executing cl.exe.
workespace3.obj - 7 error(s), 0 warning(s)
不要使用include文件的.h
形式,这些形式是为了与C向后兼容。例如使用#include <string>
。
您有许多错误:
1-您正在使用不推荐使用的头文件。标准C++库头文件的头文件中没有".h"。因此,这将是:
#include <iostream>
#include <fstream>
#include <string>
2-getche()不是一个合适的ifstream方法。以下是ifstream的完整方法列表:
http://www.cplusplus.com/reference/fstream/ifstream/
您可能打算使用get()或getline()
3-您在"cin"answers"s"之间缺少">>"。
4-您使用的是一个非常旧的IDE。有许多更新的免费IDE。值得注意的是,您可以免费获得VC++2012 Express。它将更加符合标准,还包括更好的工具和对C++11 的支持
如果编译器支持C++98标准标头,则使用它们
#include <iostream> // no .h
如果它只支持您所包含的古老的ISO之前的标头,那么就不提namespace std
了。在那些黑暗的日子里,标准库只是被转储到全局命名空间中。
我会考虑使用本世纪的编译器;你会发现从那些对20世纪90年代记忆不太完美的人那里得到帮助更容易。
相关文章:
- Project Euler问题4的错误解决方案
- 在java中解决这段代码时面临循环中的问题
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 难以理解某些人解决IOI问题的源代码
- 节俭并发:未解决的外部问题
- IpOpt拒绝解决不受约束的问题
- 错误LNK2005无法解决问题的解决方案
- 如何解决g++问题"internal compiler error: Illegal instruction min() _GLIBCXX_USE_NOEXCEPT { return __FLT_MI
- 必须使用尾随返回类型的示例,因为无法用旧方法解决问题
- 如何解决问题"unresolved extenal symbol _DllMainCRTStartup@12"?
- 如何使用OlesetClipboard将我的COM对象放置在剪贴板上时解决问题
- 与C++析构函数相比,C#析构函数和GC并没有真正解决问题
- 没有调用函数,而是使用垃圾值.如何调用函数并解决问题
- 所有的组合算法和解决C++问题的一般方法
- 模板过载解决问题
- 对"pthread_key_create"的未定义引用;参数顺序不能解决问题
- 如何在使用cplex解决问题时设置间隙
- 选择一门语言学习真的很重要吗?他们都使用相似的技术来解决问题
- Iostream解决c++问题
- 递归是一件坏事吗?在递归似乎最有用的地方,是否有更清晰或更有效的方法来解决问题?