本文介绍了在Visual Studio 2013中使用C ++的函数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

人们提到我的问题不够明确,所以希望能让每个人都更容易重组它。



以下代码用于打印一个函数,该函数创建一个由'*'组成的箭头,例如:

1 .__ *

2 ._ * * *

3. * * * * *

4 .__ *

5 .__ *

6 .__ *



但是,我的箭头必须根据用户输入计算。箭头的参数必须采用:箭头的宽度,尾部的宽度,箭头从尾部到点的长度以及用于绘制箭头的字符(在本例中为*)



请查看代码,然后在下面我将发布我在尝试进入调试模式时收到的错误。随着人们的建议,我会更新代码。另请注意我不是C ++的专家,这是我的第一个任务。所以,如果你能为我拼出一切,就像你想要在初学者时解释一样。谢谢



People are mentioning that my question isn't clear enough so hopefully to make it easier for everyone I'm going to restructure it.

The code below is designed to print a function that creates an arrow made out of '*' for example:
1.__*
2._* * *
3.* * * * *
4.__ *
5.__ *
6.__ *

However, my arrow must be calculated from user input. The arguments of the arrow must take: The width of the arrow head, the width of the tail, length of the arrow from tail to point and the character used to draw the arrow (in this case '*')

Please take a look at the code, and then below I will post the errors I'm receiving when I try entering debug mode. I will update the code as I go along with peoples advice. Also please note I'm not an expert with C++, this is really my first task. So if you could please spell everything out for me as you would want it explained when you were a beginner. Thank you

// program to run an arrow function
// Author: Douglas Tyler
// Date: 30.10.2014
// Edited: 06.11.2014

#include <iostream>
#include <sstream>
using namespace std;


void draw_arrow(int width, int tail, int length, char draw){

	for (int i = 1; i <= width; i += 2){ //print Head width

			for (int j = 0; j<(width - i) / 2; j++) //print Tail width
				std::cout << " "; // print space

			for (int j = 0; j<(length - i) / 2; j++); // print length
			std::cout << " "; // print space

		for (int j = 0; j			std::cout << draw;

		std::cout << "\n";
	}
	//print tail 
	for (int i = 0; i < width / 2; i++){
		for (int j = 0; j<(width - tail) / 2; j++)
			std::cout << " ";
		for (int j = 0; j<tail;>			std::cout << draw;
		std::cout << std::endl;
	}


}

int main() // main function
{
	cout << "Welcome to printArrow" << endl;
	cin >> " " >> endl;

	int width_of_arrow = 0;
	int width_of_tail = -1;
	int length_of_arrow = 0;
	char drawing_char = '\0';
	std::string input;
	std::cout << "Please input the Width of the Arrow head: "; // ask the user to input arrow head width information
	std::getline(std::cin, input);
	std::stringstream(input) >> width_of_arrow;

	std::cout << "Please input the Width of the Tail: 1";
	std::getline(std::cin, input);
	std::stringstream(input) >> width_of_tail;
	if (width_of_tail == -1) width_of_tail = 1;

	std::cout << "Please input the length of the Arrow: ";
	std::getline(std::cin, input);
	std::stringstream(input) >> length_of_arrow;
	if (length_of_arrow == -2) length_of_tail = 2;

	std::cout << "Input Drawing Character: *";
	std::getline(std::cin, input);
	drawing_char = input[0];
	if (drawing_char == '\0') drawing_char = '*';

	draw_arrow(width_of_arrow, width_of_tail, length_of_arrow, drawing_char);
	return 0;
} 



错误1错误C2086:'std :: string input':重新定义

错误2错误C2065:'length_of_arrow' :未声明的标识符

错误3错误C2065:'length_of_arrow':未声明的标识符

错误4错误C2065:'length_of_arrow':未声明的标识符

错误5智能感知:标识符length_of_arrow未定义



这对你们中的一些人来说可能看起来很简单,但对我来说不是这样,所以我感谢你的理解。谢谢你任何帮助你可以给


Error 1 error C2086: 'std::string input' : redefinition
Error 2 error C2065: 'length_of_arrow' : undeclared identifier
Error 3 error C2065: 'length_of_arrow' : undeclared identifier
Error 4 error C2065: 'length_of_arrow' : undeclared identifier
Error 5 IntelliSense: identifier "length_of_arrow" is undefined"

This may seem simple to some of you but it isn't to me so I appreciate you being understanding. Thank you for any help you can give

推荐答案

      void draw_arrow(int width, int tail, char draw, int length){
Line 62:   draw_arrow(width_of_arrow, width_of_tail, drawing_char);





对我来说显而易见。



Seems obvious to me.


// program to run an arrow function
// Author: Douglas Tyler
// Date: 30.10.2014
// Edited: 06.11.2014

#include <iostream>

using namespace std;


void draw_arrow(int width, int tail, int length, char draw)
{

	for (int i = 1; i <= width; i += 2)
	{
		//print Head width

		for (int j = 0; j < (width - i) / 2; j++) //print Tail width
			cout << " "; // print space

		for (int j = 0; j < (length - i) / 2; j++) // print length
			cout << " "; // print space

		for (int j = 0; j < (width - i) / 2; j++) // not sure what you want here			
			cout << draw;

		cout << endl;
	}
	//print tail 
	for (int i = 0; i < width / 2; i++)
	{
		for (int j = 0; j < (width - tail) / 2; j++)
			cout << " ";
		for (int j = 0; j < tail;) // not sure about this either
			cout << draw;
		cout << endl;
	}

}

int main() // main function
{

	int width_of_arrow = 0;
	int width_of_tail = -1;
	int length_of_arrow = 0;
	char drawing_char = '\0';


	cout << "Welcome to printArrow" << endl;
	cout << "Please input the Width of the Arrow head: "; // ask the user to input arrow head width information
	cin >> width_of_arrow;

	std::cout << "Please input the Width of the Tail: 1 ";
	cin >> width_of_tail;
	if (width_of_tail == -1)
		width_of_tail = 1;

	cout << "Please input the length of the Arrow: 2 ";
	cin >> length_of_arrow;
	if (length_of_arrow == -2)
		length_of_arrow = 2;

	cout << "Input Drawing Character: * ";
	cin >> drawing_char;
	if (drawing_char == '\0')
		drawing_char = '*';

	draw_arrow(width_of_arrow, width_of_tail, length_of_arrow, drawing_char);
	return 0;
}
</iostream>


这篇关于在Visual Studio 2013中使用C ++的函数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 08:27