注册 登录
编程论坛 新人交流区

请教关于c++编译输出的一个问题

寒天雪地 发布于 2007-10-28 20:20, 347 次点击
#include <iostream>
#include <stdafx>
#include <string>
usint namespace std;
int main(){
string strinfo="Please input your name:";
cout<<strinfo ;
cin>>strinfo;
return 0;
}

为什么结果编译出了问题:fatal error C1010: unexpected end of file while looking for precompiled header directive
执行 cl.exe 时出错.
希望高手指点,谢谢!
6 回复
#2
songying2007-10-28 20:24
我也遇到过这种情况,不知道是怎么回事呢。
#3
xiaxin2007-10-28 21:20
#include <iostream>
//#include <stdafx>
#include <string>
using namespace std;
int main()
{
string strinfo="Please input your name:";
cout<<strinfo ;
cin>>strinfo;
return 0;
}
这样改是否符合题意?
我还没有用过这样来定义字符串,可以介绍一下吗?
#4
xiaxin2007-10-28 21:44
也许是<stdafx>拼写错误吧,程序根本不能跑起来.
而上面的却可以,请你别忘了,给我介绍介绍STRING头文件的用法,谢谢了.
#5
参股银行2007-10-28 22:19
只熟悉VB呢
#6
寒天雪地2007-10-29 10:58
回复:(songying)我也遇到过这种情况,不知道是怎么...

那就介绍一下std::string用法
string来代替char * 数组,
1、Define
string s1 = "hello";
string s2 = "world";
string s3 = s1 + "," + s2 +"!\n";
2、append
s1 += ",shanshan\n";
3、Compare
if(s1 == s2)
.....
else if(s1 == "hello")
.....
4、 string 重载了许多操作符,包括 +, +=, <, =, , [], <<, >>等,正式这些操作符,对字符串操作非常方便
#include <string>
#include <iostream>
using namespace std;
int main(){
string strinfo="Please input your name:";
cout << strinfo ;
cin >> strinfo;
if( strinfo == "winter" )
cout << "you are winter!"<<endl;
else if( strinfo != "wende" )
cout << "you are not wende!"<<endl;
else if( strinfo < "winter")
cout << "your name should be ahead of winter"<<endl;
else
cout << "your name should be after of winter"<<endl;
strinfo += " , Welcome to China!";
cout << strinfo<<endl;
cout <<"Your name is :"<<endl;
string strtmp = "How are you? " + strinfo;
for(int i = 0 ; i < strtmp.size(); i ++)
cout<<strtmp[i];
return 0;
}

不过这些都是以前的版本了!
现在不常用了,在读以前的源代码时会碰到!

#7
小小牙骋2007-10-29 12:46
我这根本就编译不了???
1