| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1920 人关注过本帖
标题:为什么cout输出不了string字符串
只看楼主 加入收藏
Hlover_c
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-5-3
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
为什么cout输出不了string字符串
#include "stdafx.h"
#include "iostream"
#include "iomanip"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    string stringA = "Hello word"; //定义string类型的字符串
    cout << stringA << endl;
    string stringB(stringA);//用另一个字符串初始化字符串
    cout << "stringB= " << stringB << endl;
    string strCopy1, strCopy2;
    strCopy1 = stringA;//字符串之间的赋值运算
    cout << "strCopy1= " << strCopy1 << endl;
    strCopy2.assign(strCopy1);//将字符串赋值给本对象,相当于=操作
    strCopy2.append("programing");
    cout << "strCopy2= " << strCopy2 << endl;
    strCopy2.insert(6, "hello");
    cout << "strCopy2= " << strCopy2 << endl;
    string strADD = "in c++. ";
    stringB = stringA +  strADD;
    cout << "stringB = " << stringB << endl;

    int nLocation = stringA.find_first_of("WXYZ");
    cout << "The first position of w in stringA is " << nLocation << endl;
    int nCom = (stringB);
    cout << "compare of stringA and stringB is " << nCom << endl;

}
问题是cout<<string<<endl;//string前面的<<一直报错提示
1>          d:\app\visualstudio2013\vc\include\ostream(699): 或       “std::basic_ostream<char,std::char_traits<char>> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,const char *)”
搜索更多相关主题的帖子: include 字符串 
2017-05-16 23:28
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9026
专家分:54030
注 册:2011-1-18
收藏
得分:10 
string是类型名称,还是变量?
2017-05-17 00:01
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9026
专家分:54030
注 册:2011-1-18
收藏
得分:0 
帮你代码排版了一下

程序代码:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main( void )
{
    string stringA = "Hello word";
    cout << stringA << endl;

    string stringB(stringA);
    cout << "stringB= " << stringB << endl;

    string strCopy1;
    strCopy1 = stringA;
    cout << "strCopy1= " << strCopy1 << endl;

    string strCopy2;
    strCopy2.assign(strCopy1);
    strCopy2.append("programing");
    cout << "strCopy2= " << strCopy2 << endl;

    strCopy2.insert(6, "hello");
    cout << "strCopy2= " << strCopy2 << endl;

    string strADD = "in c++. ";
    stringB = stringA +  strADD;
    cout << "stringB = " << stringB << endl;

    int nLocation = stringA.find_first_of("WXYZ");
    cout << "The first position of w in stringA is " << nLocation << endl;

    int nCom = (stringB);
    cout << "compare of stringA and stringB is " << nCom << endl;
}

2017-05-17 08:18
yangfrancis
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:141
帖 子:1510
专家分:7661
注 册:2014-5-19
收藏
得分:10 
头文件<string>
2017-05-17 10:02
快速回复:为什么cout输出不了string字符串
数据加载中...
 
   



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

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