我有一个关于指向2d数组的指针的问题.如果数组是这样的
int a[2][3];
Run Code Online (Sandbox Code Playgroud)
那么,这是一个指向数组的指针a吗?
int (*p)[3] = a;
Run Code Online (Sandbox Code Playgroud)
如果这是正确的,我想知道什么[3]意思int(*p)[3]?
嗨,我是C++的新手,我试图从一个函数返回一个二维数组.就是这样的
int **MakeGridOfCounts(int Grid[][6])
{
int cGrid[6][6] = {{0, }, {0, }, {0, }, {0, }, {0, }, {0, }};
return cGrid;
}
Run Code Online (Sandbox Code Playgroud) 我是C的新手.我试图从一个函数返回一个二维数组.就是这样的
int *MakeGridOfCounts(int Grid[][6])
{
int cGrid[6][6] = {{0, }, {0, }, {0, }, {0, }, {0, }, {0, }};
int (*p)[6] = cGrid;
return (int*)p;
}
Run Code Online (Sandbox Code Playgroud)
我知道这会导致错误,需要帮助.谢谢
我只是想从文件中读取每个字符并在屏幕上打印它们.为了测试,我尝试在打印字符之前首先在控制台屏幕上打印ascii值.
我试图阅读的文件内容如下:
assign1_2.cpp:33:20: error: cannot convert 'std::string
{aka std::basic_string<char>}' to 'const char*' for argument '1'
to 'int atoi(const char*)'
Run Code Online (Sandbox Code Playgroud)
我使用下面的代码
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <stdlib.h>
using namespace std;
void CountLetters(string filename);
int main()
{
CountLetters("count.txt");
}
void CountLetters(string filename)
{
cout << filename << endl;
ifstream in;
in.open(filename.c_str(), ios::in);
vector<char> letter;
char temp;
while (!in.eof())
{
cout << in.get() << endl;
}
in.close();
}
Run Code Online (Sandbox Code Playgroud)
运行这些代码后,我在控制台屏幕的末尾看到"-1".有人请解释一下?谢谢
我正在尝试实现一个显示文件名的工具.我想通过使用SetWindowText()方法来做到这一点.但是,当我尝试在循环中使用此方法时,文本显示在一行中,并不断刷新.
这是代码片段
for (int i = 0; i<10; i++)
{
SetWindowText(filenames);
}
Run Code Online (Sandbox Code Playgroud)
请帮忙.!谢谢.
我正在尝试实现Matrix的附加功能.(也就是说,添加两个矩阵)我这样做是通过重载加法函数使得可以添加两个矩阵.对于这个Matrix类,我继承了Grid类来实现.
我__add__这里的方法似乎有问题,但可以搞清楚.错误说AttributeError: 'Matrix' Object has no attibute '_data'.
这是我的代码.请任何人可以帮忙吗?或解释?
谢谢
from Grid import Grid
class Matrix(Grid):
def __init__(self, m, n, value=None):
self.matrix = Grid(m, n)
self.row = m
self.col = n
def insert(self, row, col, value):
self.matrix[row][col] = value
print self.matrix
def __add__(self, other):
if self.row != other.row and self.column != other.column:
print " Matrixs are not indentical."
else:
for row in xrange(self.row):
for col in xrange(self.col):
self.matrix[row][col] = self.matrix[row][col] + other[row][col]
return self.matrix
Run Code Online (Sandbox Code Playgroud)
这是我继承的Grid类.
from …Run Code Online (Sandbox Code Playgroud) 我不太明白这个功能是如何工作的.
我写了一个简单的编程,用getline()读取一行.
例如:
ifstream in;
in.open("example.txt");
string line;
getline(in, line);
cout << line << endl;
Run Code Online (Sandbox Code Playgroud)
当我尝试运行此程序时,我收到了这样的错误消息.
`assign1_2.cpp:33:20: error: cannot convert 'std::string {aka std::basic_string<char>}' to 'const char*' for argument '1' to 'int atoi(const char*)'
Run Code Online (Sandbox Code Playgroud)
我根本不明白这里出了什么问题.请帮忙!.我是c ++的新手.
我想用显示功能打印self.row.但是,错误说明当类成员显然没有这样的self.row属性时.
请有人向我解释我做错了什么吗?
谢谢.
from Grid import Grid
class Matrix(Grid):
def _init__(self, m, n, value=None):
Grid.__init__(m, n)
self.row = m
self.col = n
def display(self):
print self.row
Run Code Online (Sandbox Code Playgroud)