C++中cout輸出字符串和字符串型指針地址值的方法以及C語言中的printf用法比較


#include <iostream>
using namespace std;
#include <stdio.h>
int main()
{
	char *pstr = "china";
	char *qstr = "america";
	char *q = "adf";
	char * s;
	s = "hello";

	printf("pstr = %p\n", pstr);  /*輸出為字符串起始地址值*/
	/*由於C++標准庫中I / O類對 << 操作符重載,因此在遇到字符型指針時會將其當作字符串名來處理,輸出指針所指的字符串。
	https://blog.csdn.net/u013467442/article/details/43666955 */
	cout << "pstr = " << pstr << endl;  /*輸出為字符串*/
	printf("pstr = %s\n", pstr);  /*輸出為字符串*/
	
	cout << "qstr = " << qstr << endl;
	cout << "q = " << q << endl;
	cout << "s = " << s << endl;
	printf("s = %p\n", s);
	return 0;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM