你好noob程序员在这里遇到strcmp问题这是我的代码.
while (strcmp("m",wood) !=0 || strcmp("j",wood) !=0 || strcmp("o",wood) !=0){
cout << "(m for mahogany, o for oak, or p for pine): ";
cin >> wood;
}
Run Code Online (Sandbox Code Playgroud)
这是我的错误.
您好,这是我的代码段,我正在尝试实现Morris-Pratt算法.当我比较我的变量时,如果发现它们不匹配,这是因为我的一个变量"Temp"正在将额外的字符添加到数组的末尾.这是我的代码......
// Calculate the next talbe
char test[searchLen];
for(int i = 0; i < searchLen; i++)
{
test[i] = fileContent[currPos+i];
}
cout << "SEARCHLEN: " << searchLen << endl;
cout << "TEST: " << '\t' << '\t' << test << endl;
cout << "SEARCH: " << '\t' << search << endl;
cout << strcmp(test,search) << endl << endl;
// Determine if a match is detected
if(strcmp(test,search)==0)
{
cout << "----------------------> Match detected at: " << currPos << endl;
}
currPos …Run Code Online (Sandbox Code Playgroud) 我将指针转换为向量时遇到问题char *.这是我的代码,我做错了什么?
char * Word1 = (*fileRead)[i].c_str();
char * Word2 = dict[j].c_str();
if(WordCmp(Word1,Word2)
{
found = true;
}
Run Code Online (Sandbox Code Playgroud)
这是函数头WordCmp().
int WordCmp(char* Word1, char* Word2);
Run Code Online (Sandbox Code Playgroud)
我得到的错误如下:
server.cpp:200: error: invalid conversion from 'const char*' to 'char*'
server.cpp:201: error: invalid conversion from 'const char*' to 'char*'
Run Code Online (Sandbox Code Playgroud) 你好,我需要一只手正确地产生一个线程,我似乎无法正确的语法.这是我的代码......
// Spawn a thread--------------------------------------------------#
pthread_t thread1; // thread object
int rc1;
if( (rc1=pthread_create( &thread1, NULL, spellCheck, NULL)) )
{
cout << "Thread creation failed: " << rc1 << endl;
}
pthread_join( thread1, NULL);
Run Code Online (Sandbox Code Playgroud)
功能定义
void spellCheck(vector<string> * fileRead, list<string> * incorrectWord, vector<string> * correctWord)
{
Run Code Online (Sandbox Code Playgroud)
头文件
void spellCheck(vector<string> *fileRead, list<string> *incorrectWord, vector<string> *correctWord);
Run Code Online (Sandbox Code Playgroud)
任何帮助将非常感激 :)
我的错误:
server.cpp:142: error: invalid conversion from 'void ()(std::vector<std:................. initializing argument 3 of 'int pthread_create(pthread_t, const pthread_attr_t*, void* ()(void), void*)'
Run Code Online (Sandbox Code Playgroud) 我无法访问以下向量.我是向量的新手,所以这可能是一个很小的语法,我做错了.这是代码....
void spellCheck(vector<string> * fileRead)
{
string fileName = "/usr/dict/words";
vector<string> dict; // Stores file
// Open the words text file
cout << "Opening: "<< fileName << " for read" << endl;
ifstream fin;
fin.open(fileName.c_str());
if(!fin.good())
{
cerr << "Error: File could not be opened" << endl;
exit(1);
}
// Reads all words into a vector
while(!fin.eof())
{
string temp;
fin >> temp;
dict.push_back(temp);
}
cout << "Making comparisons…" << endl;
// Go through each word in vector
for(int i=0; …Run Code Online (Sandbox Code Playgroud) 你好我是新的bash脚本,我有一个简单的程序,不适合我.我认为它是一个语法错误.
#!/bin/bash
#example1.sh
read Age
if ["$Age" -lt "18"]; then
echo "You must go to school"
fi
Run Code Online (Sandbox Code Playgroud)
当我输入1时,它说[1:命令未找到
您好我在将图像绘制到我的框架上时出错.我不确定这里出了什么问题.
我在这里得到以下错误.
Java: 77: cannot find symbol
symbol: variable image
location: class DrawComponent
g.drawImage(image, 0, 0, null);
class DrawComponent extends JComponent {
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
// draw a circle with the same center
double centerX = 250;
double centerY = 180;
double radius = 20;
Ellipse2D circle = new Ellipse2D.Double();
circle.setFrameFromCenter(centerX, centerY, centerX + radius, centerY + radius);
g2.setPaint(Color.RED);
g2.fill(circle);
g2.draw(circle);
String filename = "SydneyOperaHouse.jpeg";
try{
Image image = ImageIO.read(new File(filename));
}catch(IOException ex){ …Run Code Online (Sandbox Code Playgroud)