关于把字符串变量赋值到字符串数组的问题

scate 2008-01-09 06:11:23
现在有
CString str1;
int i,row,col;
char str[30][400];
row=1; col=1; //row和col是表格的行和列


现在需要在条件 for(row = 1; row <5;row++)
for( col = 1; col < 8;col++)

执行 str1=GetItem(row,col) //把单元内容放到str1里
然后问题就来了,str1取得内容之后,就要放到数组 str[30][400]的第一个成员里,然后str1又去取下一个单元,再放到第二个数组成员里,如此类推
我现在已经顺利取出第一个表格单元的内容并放到了str1里,要怎么把值传到str[30][400]里?
直接 str[0]=str1 出现 cannot convert from 'class CString' to 'char 错误
应该怎么弄?
...全文
373 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
菜牛 2008-01-10
  • 打赏
  • 举报
回复
字符串操作需要用strcpy来拷贝,不能直接赋值;另外,为什么不用CStringArray来保存字符串数组?
scate 2008-01-10
  • 打赏
  • 举报
回复
to mackz:
该怎么做?没用过CStringArray
zhangbinjn 2008-01-09
  • 打赏
  • 举报
回复
Example
// basic_string_c_str.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

int main( )
{
using namespace std;

string str1 ( "Hello world" );
cout << "The original string object str1 is: "
<< str1 << endl;
cout << "The length of the string object str1 = "
<< str1.length ( ) << endl << endl;

// Converting a string to an array of characters
const char *ptr1 = 0;
ptr1= str1.data ( );
cout << "The modified string object ptr1 is: " << ptr1
<< endl;
cout << "The length of character array str1 = "
<< strlen ( ptr1) << endl << endl;

// Converting a string to a C-style string
const char *c_str1 = str1.c_str ( );
cout << "The C-style string c_str1 is: " << c_str1
<< endl;
cout << "The length of C-style string str1 = "
<< strlen ( c_str1) << endl << endl;
}
Output
The original string object str1 is: Hello world
The length of the string object str1 = 11

The modified string object ptr1 is: Hello world
The length of character array str1 = 11

The C-style string c_str1 is: Hello world
The length of C-style string str1 = 11
这是MSDN中的一个例子希望对你的问题有帮助!!!
happyprince 2008-01-09
  • 打赏
  • 举报
回复
用memcpy()
ryfdizuo 2008-01-09
  • 打赏
  • 举报
回复
查一下CString的函数吧...
cstring里面到是有string::c_str()函数返回为const char*类型的

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧