我编写了如下一段程序:
#include <iostream.h>
#include <string.h>
int main()
{
string word;
while (cin>>word)
cout<<"word read is:"<<word<<'\n';
cout<<"ok:no more words to read:bye!\n";
return 0;
}
但我在生成程序的时候,出现了如下一些错误:
d:\Microsoft Visual Studio .NET\Vc7\include\useoldio.h(29): warning C4995: “_OLD_IOSTREAMS_ARE_DEPRECATED”:名称被标记为否决的 #pragma
d:\My Documents\Program\C++ Primer\16\16.cpp(5): error C2065: “String” : 未声明的标识符
d:\My Documents\Program\C++ Primer\16\16.cpp(5): error C2146: 语法错误 : 缺少“;”(在标识符“word”的前面)
d:\My Documents\Program\C++ Primer\16\16.cpp(5): error C2065: “word” : 未声明的标识符
d:\My Documents\Program\C++ Primer\16\16.cpp(6): error C2593: “operator >>”不明确
d:\My Documents\Program\C++ Primer\16\16.cpp(6): fatal error C1903: 无法从以前的错误中恢复;正在停止编译 我的VS.NET是装在D盘的,C盘是我的XP系统盘,我的这个程序使用的是WIN32模板的控制台应用程序,不知道是我的VS.NET没有装好呢还是我的程序有问题?(这个程序是c++ primer上的第一个程序,应该没问题吧!)请各位高手帮小弟解决一下!在下有礼了!
#include <iostream.h>
#include <string.h>
int main()
{
string word;
while (cin>>word)
cout<<"word read is:"<<word<<'\n';
cout<<"ok:no more words to read:bye!\n";
return 0;
}
但我在生成程序的时候,出现了如下一些错误:
d:\Microsoft Visual Studio .NET\Vc7\include\useoldio.h(29): warning C4995: “_OLD_IOSTREAMS_ARE_DEPRECATED”:名称被标记为否决的 #pragma
d:\My Documents\Program\C++ Primer\16\16.cpp(5): error C2065: “String” : 未声明的标识符
d:\My Documents\Program\C++ Primer\16\16.cpp(5): error C2146: 语法错误 : 缺少“;”(在标识符“word”的前面)
d:\My Documents\Program\C++ Primer\16\16.cpp(5): error C2065: “word” : 未声明的标识符
d:\My Documents\Program\C++ Primer\16\16.cpp(6): error C2593: “operator >>”不明确
d:\My Documents\Program\C++ Primer\16\16.cpp(6): fatal error C1903: 无法从以前的错误中恢复;正在停止编译 我的VS.NET是装在D盘的,C盘是我的XP系统盘,我的这个程序使用的是WIN32模板的控制台应用程序,不知道是我的VS.NET没有装好呢还是我的程序有问题?(这个程序是c++ primer上的第一个程序,应该没问题吧!)请各位高手帮小弟解决一下!在下有礼了!
using namespace std;
#include <string> using namespace std;int main()
{
string word;
while (cin>>word)
cout<<"word read is:"<<word<<'\n';
cout<<"ok:no more words to read:bye!\n";
return 0;
}
注意ISO标准C++的头文件都没有.h扩展名的。并且几乎所有的类都在std名空间中,使用使之前要先using namespace std。你既然在看C++ Primer,它应该会讲到这些的吧。