我从教程中复制了这段代码来玩,但是我继续得到一个错误,声明我不能有任何空字符常量.该教程是在VS 2008中,我正在使用VS 2013,所以也许这不再有效,但我找不到任何修复.这是代码:
#include "stdafx.h"
#include <iostream>
class MyString
{
private:
char *m_pchString;
int m_nLength;
public:
MyString(const char *pchString="")
{
// Find the length of the string
// Plus one character for a terminator
m_nLength = strlen(pchString) + 1;
// Allocate a buffer equal to this length
m_pchString = new char[m_nLength];
// Copy the parameter into our internal buffer
strncpy(m_pchString, pchString, m_nLength);
// Make sure the string is terminated
//this is where the error occurs
m_pchString[m_nLength-1] = '';
}
~MyString() …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个带有编号轴的图表。但是,我似乎无法减小这些数字之间的间距。这是我用来减少paintComponent方法中数字之间的间距的当前代码,但它似乎不起作用:
super.paintComponent(g);
Map<TextAttribute, Object> attributes = new HashMap<TextAttribute, Object>();
attributes.put(TextAttribute.TRACKING, 0.5);
Font font = new Font("Monospaced", Font.PLAIN, 1);
Font font2 = font.deriveFont(attributes);
g.setFont(font2);
Run Code Online (Sandbox Code Playgroud)
显示数字时,它们之间的间距与以前相同。
我尝试过减少方法中的0.5 attributes.put(),但似乎并没有减少间距。我也尝试过TextAttribute.KERNING并使用TextAttribute.KERNING_ON,但也没有成功。
任何帮助是极大的赞赏!
谢谢 :)
我正在制作一个程序,如果用户输入文本,它会将任何大写字母转换为小写:
def lowerChar(char):
if ord(char) >= 65 and ord(char) <= 90:
char = int(ord(char)) + 32
char = (chr(char))
return print(char)
else:
return print(char)
def lowerString(string):
x = len(string)
for i in range(x):
char = string[0 + i]
lowerChar(char)
result = ""
result = result + lowerChar(string[i])
string = input("type")
lowerString(string)
Run Code Online (Sandbox Code Playgroud)
错误是:
Traceback (most recent call last):
File "C:\Python34\njn.py", line 24, in <module>
lowerString(string)
File "C:\Python34\njn.py", line 19, in lowerString
result = result + lowerChar(string[i])
TypeError: Can't convert 'NoneType' object …Run Code Online (Sandbox Code Playgroud)