初始化字符串的二维数组 [英] Initializing a two dimensional array of strings

查看:73
本文介绍了初始化字符串的二维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c ++中声明字符串的二维数组?还有如何在文件中写入此字符串?

How to declare a two dimensional array of strings in c++? And also how to write this string on files?

推荐答案

一起进行声明和初始化:

Declaration and initialization together:

std::string myarray[2][3] = {
  { "hello", "jack", "dawson" }, 
  { "hello", "hello", "hello" }
};

对于写入文件,templatetypedef的答案几乎可以,除非您应该进行错误检查并在完成后关闭输出文件流.

For writing to file, templatetypedef's answer is almost fine, except you should do error checking and close the output file stream when done.

这篇关于初始化字符串的二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆