Write,writeline,WriteString函数(来自网络,全是粘贴,收集自己用)
来源:互联网 发布:程序员培训班多少钱 编辑:程序博客网 时间:2024/04/27 22:27
Console类中的Write和WriteLine函数都是用来在控制台上输出字符串或含有变量的复合文本。其中,WriteLine函数用于在控制台上输出一行文本,并自动换行;而Write函数输出后不会自动换行。
对于Write和WriteLine函数来说,都可以将各种基本类型的值、对象直接输出到控制台中,且WriteLine函数可以不带参数,直接换行。
【例Ex_Write】控制台输出
#include "stdafx.h"
using namespace System;
int main(array<System::String ^> ^args)
{
int n;
Console::Write(L"请输入杨辉三角的阶数:");
n = Int32::Parse( Console::ReadLine() );
array<int>^ curLineArr = nullptr;
for (int i=0; i<n; i++ )
{
array<int>^ nextLineArr = gcnew array<int>( i+1 );
if ( i<=1 ){
for ( int j=0; j<i+1; j++ )
nextLineArr[j] = 1;
} else {
if ( curLineArr->Length > 1 ){
nextLineArr[0] = 1;
for ( int k=0; k<curLineArr->Length-1; k++ )
{
nextLineArr[k+1] = curLineArr[k] + curLineArr[k+1];
}
nextLineArr[nextLineArr->Length - 1] = 1;
}
}
// 计算输出该行数据前面的空格
String^ strSpace = " "; // 3个空格
Console::Write( strSpace->PadLeft( ( n - i ) * 3 ) );
// 输出该行数据
for each ( int data in nextLineArr )
Console::Write(L"{0, 6}", data );
Console::WriteLine(); // 直接换行
curLineArr = nextLineArr;
}
return 0;
}
编译运行,输入10并按【Enter】键,结果如下:
请输入杨辉三角的阶数:10
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
CStdioFile::WriteString
Writes data from a buffer to the file associated with the CStdioFile object.
virtual void WriteString( LPCTSTR lpsz );
Parameters
- lpsz
Specifies a pointer to a buffer containing a null-terminated text string.
The terminating null character ('\0') is not written to the file. Any newline character in lpsz is written to the file as a carriage return–linefeed pair.
WriteString throws an exception in response to several conditions, including the disk-full condition.
This is a text-oriented write function available to CStdioFile and its descendents, and to CArchive. CFile::Write is also available, but rather than terminating on a null character, it writes the requested number of bytes to the file.
// example for CStdioFile::WriteStringextern CStdioFile f;char buf[] = "test string";f.WriteString( buf );
CFile::Write
Writes data from a buffer to the file associated with the CFile object.
virtual void Write( const void* lpBuf, UINT nCount );
Parameters
- lpBuf
A pointer to the user-supplied buffer that contains the data to be written to the file.
- nCount
The number of bytes to be transferred from the buffer. For text-mode files, carriage return–linefeed pairs are counted as single characters.
Write throws an exception in response to several conditions, including the disk-full condition.
//example for CFile::Writeextern CFile cfile;char pbuf[100];cfile.Write( pbuf, 100 );
- Write,writeline,WriteString函数(来自网络,全是粘贴,收集自己用)
- ASP常用函数大收集01[大部分来自网络]
- Console.Write和Console.WriteLine
- C#版杨辉三角形 write和writeline啊。。。
- C#中WriteLine与Write的区别
- Console.Write()与Console.WriteLine()的区别
- 来自youtube 的pv3d视频教程 --------很全的收集
- Java中需要理解的问题----收集来自网络
- 可借鉴的C++爬虫范本---来自网络收集
- 网络编程中的read,write函数
- 网络编程中的read,write函数
- 网络编程-read()/write()/assert()函数
- [来自网络]Sql汉字转拼音全拼
- socket函数read write send和recv 收集整理
- 理解标准输出流方法:WriteLine和Write
- c#write和 writeline read和 readline 的区别
- C#编程中Console.Write()和Console.WriteLine()的区别
- C#中Console.WriteLine(),Console.Write()的用法
- java基础1
- vs2010编译Qt4.8.4
- C#委托,事件。
- BUCT-OJ 2060 数字三角形4
- C#如何为winform程序打包发布应用(图解)
- Write,writeline,WriteString函数(来自网络,全是粘贴,收集自己用)
- hdu1998奇数阶魔方
- 排序,折半查找
- Java操作PDF之itext入门
- 以前学习的jquery mobile的一些笔记
- 实验四十三Windows Server 2012 RDS桌面虚拟化之十四RemoteApp应用程序的安全管理和会话限制
- iPhone开发基础教程 笔记
- AChartEngine实现Android实时曲线绘制
- C# var标识符 和 dynamic关键字