首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

c 字符指针,该怎么解决

2012-03-11 
c 字符指针// myProject.cpp : Defines the entry point for the console application.//#include stdafx

c 字符指针
// myProject.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

int test()
{
char *str[] = {
"ertyuiop",
"dfghjk",
"ertyuio"
};

for(int i=0;i<3;i++)
{
printfln("--------",*str[i]); //为什么没有输出?
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{  
test();
system("pause");
return 0;
}


[解决办法]
*str[i]

str[i]就行了 或者 *(str+i);
[解决办法]

C/C++ code
printfln("--------",*str[i]); //为什么没有输出?
[解决办法]
printfln这个不懂,如果是要用printf()的话,头文件要包含stdio.h,格式化要加%s,看你的头文件是iostream,应该用cout,*str【i】这个只能输出第一个字符
[解决办法]
看LZ的意图是要输出字符串,
首先printf(...)需要格式化,用%s,
然后寻址的时候只需要str[i]就可以了,str的元素本身就是指针。

热点排行