标题:谁能帮我看下这程序出什么问题了,先谢谢了!
取消只看楼主
ToMoRRoWa
Rank: 1
来 自:保密
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-4-17
结帖率:66.67%
已结贴  问题点数:20 回复次数:1 
谁能帮我看下这程序出什么问题了,先谢谢了!

#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <iomanip>
#include <cerrno>

using std::cin;
using std::cout;
using std::endl;
using std::setw;

int _tmain(int argc, _TCHAR* argv[])
{
    const int MAX = 50;
    char Str1[MAX];
    char Str2[MAX];
    char* instead[MAX];
   
    cout << "请输入目标字符串:";
    cin.getline( Str1,MAX,'\n');
    cout << "请输入源字符串:";
    cin.getline( Str2,MAX,'\n');
   
    int count = 0;
    while( Str2 != 0 )
    {
        count ++;
        instead[count] = &Str2[count];
    }
    errno_t error = strcat_s(Str1,MAX,*instead);

    if( error == 0 )
    {
        cout << "恭喜,字符串拼接成功!"
             << endl
                << "拼接结果:" << strcat(Str1,*instead);
    }
    else
        if( error == EINVAL )
        cout << "字符串拼接失败,原因是目标或源为NULL";
    else
        if( error == ERANGE)
        cout << "字符串拼接失败,原因是目标长度太短";
    cout << endl
         << "Press any key . . .";
    _getch();
    return 0;
}
搜索更多相关主题的帖子: instead include 字符串 目标 
2010-05-02 16:47
ToMoRRoWa
Rank: 1
来 自:保密
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-4-17
得分:0 
// 拼接字符串.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <iomanip>
#include <cerrno>
#include <cstring>

using std::cin;
using std::cout;
using std::endl;
using std::setw;

int _tmain(int argc, _TCHAR* argv[])
{
    const int MAX = 50;
    char Str1[MAX];
    char Str2[MAX];
    char* instead[MAX];
    int point = NULL;
   
    cout << "请输入目标字符串:";
    cin.getline( Str1,MAX,'\n');
    cout << "请输入源字符串:";
    cin.getline( Str2,MAX,'\n');
   
    int count = 0;
    while( point != '\0');
    {
        count ++;
        instead[count] = &Str2[count];
        point = Str2[count];
    }
    errno_t error = strcat_s(Str1,MAX,*instead);

    if( error == 0 )
    {
        cout << "恭喜,字符串拼接成功!"
             << endl
                << "拼接结果:" << strcat(Str1,*instead);
    }
    else
        if( error == EINVAL )
        cout << "字符串拼接失败,原因是目标或源为NULL";
    else
        if( error == ERANGE)
        cout << "字符串拼接失败,原因是目标长度太短";
    cout << endl
         << "Press any key . . .";
    _getch();
    return 0;
}
2010-05-02 17:30



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-305146-1-1.html




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

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