| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3004 人关注过本帖
标题:[em03]string类的输入问题
只看楼主 加入收藏
weikie
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2006-4-19
收藏
 问题点数:0 回复次数:5 
[em03]string类的输入问题

小弟请教下一个string类怎么实现输入啊 有库函数吗?
紧急啊 大哥们

搜索更多相关主题的帖子: string 输入 
2006-04-28 21:23
无限忧伤
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2006-4-5
收藏
得分:0 
利用字符数组间接输入,比如
#include "iostream.h"
#include "afx.h"
void main()
{char c[80];
CString st1;
cout<<"输入字符串:";
cin>>c;
st1=c;
cout<<"输出结果:";
cout <<st1<<endl;
}

2006-04-28 21:49
lbwxqh
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2006-4-12
收藏
得分:0 
直接就可以输入啊
#include <string>
using namespace std;
void main()
{
string str;
cin>>str;
cout<<str;
}
2006-04-29 12:28
无限忧伤
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2006-4-5
收藏
得分:0 

用了楼上的程序怎么报错啊?
--------------------Configuration: yes - Win32 Debug--------------------
Compiling...
yes.cpp
f:\visual c++6.0\vc++\msdev98\myprojects\yes\yes.cpp(6) : error C2065: 'cin' : undeclared identifier
f:\visual c++6.0\vc++\msdev98\myprojects\yes\yes.cpp(6) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::operator >>(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument for 'cl
ass std::basic_istream<_E,_Tr> &' from 'int'
f:\visual c++6.0\vc++\msdev98\myprojects\yes\yes.cpp(6) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::operator >>(class std::basic_istream<_E,_Tr> &,short *)' : could not deduce template argument for 'class std::basic_istream<_E,_Tr
> &' from 'int'
f:\visual c++6.0\vc++\msdev98\myprojects\yes\yes.cpp(6) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::operator >>(class std::basic_istream<_E,_Tr> &,unsigned char &)' : could not deduce template argument for 'class std::basic_istrea
m<_E,_Tr> &' from 'int'
f:\visual c++6.0\vc++\msdev98\myprojects\yes\yes.cpp(6) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::operator >>(class std::basic_istream<_E,_Tr> &,unsigned char *)' : could not deduce template argument for 'class std::basic_istrea
m<_E,_Tr> &' from 'int'
f:\visual c++6.0\vc++\msdev98\myprojects\yes\yes.cpp(6) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::operator >>(class std::basic_istream<_E,_Tr> &,signed char &)' : could not deduce template argument for 'class std::basic_istream<
_E,_Tr> &' from 'int'
f:\visual c++6.0\vc++\msdev98\myprojects\yes\yes.cpp(6) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::operator >>(class std::basic_istream<_E,_Tr> &,signed char *)' : could not deduce template argument for 'class std::basic_istream<
_E,_Tr> &' from 'int'
f:\visual c++6.0\vc++\msdev98\myprojects\yes\yes.cpp(6) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::operator >>(class std::basic_istream<_E,_Tr> &,_E &)' : could not deduce template argument for 'class std::basic_istream<_E,_Tr> &
' from 'int'
f:\visual c++6.0\vc++\msdev98\myprojects\yes\yes.cpp(6) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::operator >>(class std::basic_istream<_E,_Tr> &,_E *)' : could not deduce template argument for 'class std::basic_istream<_E,_Tr> &
' from 'int'
f:\visual c++6.0\vc++\msdev98\myprojects\yes\yes.cpp(6) : error C2677: binary '>>' : no global operator defined which takes type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable con
version)
f:\visual c++6.0\vc++\msdev98\myprojects\yes\yes.cpp(7) : error C2065: 'cout' : undeclared identifier
f:\visual c++6.0\vc++\msdev98\myprojects\yes\yes.cpp(7) : error C2784: 'class std::basic_ostream<_E,_Tr> &__cdecl std::operator <<(class std::basic_ostream<_E,_Tr> &,const class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument f
or 'class std::basic_ostream<_E,_Tr> &' from 'int'
f:\visual c++6.0\vc++\msdev98\myprojects\yes\yes.cpp(7) : error C2784: 'class std::basic_ostream<_E,_Tr> &__cdecl std::operator <<(class std::basic_ostream<_E,_Tr> &,const short *)' : could not deduce template argument for 'class std::basic_ostream<
_E,_Tr> &' from 'int'
f:\visual c++6.0\vc++\msdev98\myprojects\yes\yes.cpp(7) : error C2784: 'class std::basic_ostream<_E,_Tr> &__cdecl std::operator <<(class std::basic_ostream<_E,_Tr> &,const unsigned char)' : could not deduce template argument for 'class std::basic_os
tream<_E,_Tr> &' from 'int'
f:\visual c++6.0\vc++\msdev98\myprojects\yes\yes.cpp(7) : error C2784: 'class std::basic_ostream<_E,_Tr> &__cdecl std::operator <<(class std::basic_ostream<_E,_Tr> &,const unsigned char *)' : could not deduce template argument for 'class std::basic_
ostream<_E,_Tr> &' from 'int'
f:\visual c++6.0\vc++\msdev98\myprojects\yes\yes.cpp(7) : error C2784: 'class std::basic_ostream<_E,_Tr> &__cdecl std::operator <<(class std::basic_ostream<_E,_Tr> &,const signed char)' : could not deduce template argument for 'class std::basic_ostr
eam<_E,_Tr> &' from 'int'
f:\visual c++6.0\vc++\msdev98\myprojects\yes\yes.cpp(7) : error C2784: 'class std::basic_ostream<_E,_Tr> &__cdecl std::operator <<(class std::basic_ostream<_E,_Tr> &,const signed char *)' : could not deduce template argument for 'class std::basic_os
tream<_E,_Tr> &' from 'int'
f:\visual c++6.0\vc++\msdev98\myprojects\yes\yes.cpp(7) : error C2784: 'class std::basic_ostream<_E,_Tr> &__cdecl std::operator <<(class std::basic_ostream<_E,_Tr> &,_E)' : could not deduce template argument for 'class std::basic_ostream<_E,_Tr> &'
from 'int'
f:\visual c++6.0\vc++\msdev98\myprojects\yes\yes.cpp(7) : error C2784: 'class std::basic_ostream<_E,_Tr> &__cdecl std::operator <<(class std::basic_ostream<_E,_Tr> &,const _E *)' : could not deduce template argument for 'class std::basic_ostream<_E,
_Tr> &' from 'int'
f:\visual c++6.0\vc++\msdev98\myprojects\yes\yes.cpp(7) : error C2677: binary '<<' : no global operator defined which takes type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable con
version)
执行 cl.exe 时出错.

yes.exe - 1 error(s), 0 warning(s)


2006-04-29 20:49
freshman42
Rank: 1
等 级:新手上路
威 望:1
帖 子:94
专家分:0
注 册:2005-12-4
收藏
得分:0 
以下是引用lbwxqh在2006-4-29 12:28:00的发言:
直接就可以输入啊
#include <string>
#include<iostream>
using namespace std;
void main()
{
string str;
cin>>str;
cout<<str;
}


2006-04-29 21:16
hnzzc
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2006-4-26
收藏
得分:0 

可以调用函数为sting类变量赋值吗???

2006-05-07 17:18
快速回复:[em03]string类的输入问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027554 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved