src/main.cpp:8:1: error: stray ‘\302’ in program int s=0; ^ src/main.cpp:8:2: error: stray ‘\240’ in program int s=0; ^ src/main.cpp:10:1: error: stray ‘\302’ in program for(int i=n;i>0;i/=10) ^ src/main.cpp:10:2: error: stray ‘\240’ in program for(int i=n;i>0;i/=10) ^ src/main.cpp:10:13: error: stray ‘\302’ in program for(int i=n;i>0;i/=10) ^ src/main.cpp:10:14: error: stray ‘\240’ in program for(int i=n;i>0;i/=10) ^ src/main.cpp:16:1: error: stray ‘\302’ in program } ^ src/main.cpp:16:2: error: stray ‘\240’ in program } ^
时间: 2024-04-12 11:33:32 浏览: 165
这些错误提示表明在你的代码中存在一些非法的字符,导致编译错误。根据错误信息,看起来可能是一些不可见的特殊字符导致的问题。
请尝试重新复制粘贴代码,确保没有不可见字符或其他特殊字符。另外,还要确保你的代码编辑器使用的是正确的字符编码。
如果问题仍然存在,请提供完整的代码以便我能够帮助你更好地解决问题。
相关问题
Main.cc:40:18: error: stray ‘\342’ in program result = “Yes”; ^ Main.cc:40:19: error: stray ‘\200’ in program result = “Yes”; ^ Main.cc:40:20: error: stray ‘\234’ in program result = “Yes”; ^ Main.cc:40:24: error: stray ‘\342’ in program result = “Yes”; ^ Main.cc:40:25: error: stray ‘\200’ in program result = “Yes”; ^ Main.cc:40:26: error: stray ‘\235’ in program result = “Yes”; ^ Main.cc:42:18: error: stray ‘\342’ in program result = “No”; ^ Main.cc:42:19: error: stray ‘\200’ in program result = “No”; ^ Main.cc:42:20: error: stray ‘\234’ in program result = “No”; ^ Main.cc:42:23: error: stray ‘\342’ in program result = “No”; ^ Main.cc:42:24: error: stray ‘\200’ in program result = “No”; ^ Main.cc:42:25: error: stray ‘\235’ in program result = “No”; ^ Main.cc: In function ‘std::__cxx11::string solution(std::__cxx11::string, std::__cxx11::string)’: Main.cc:40:21: error: ‘Yes’ was not declared in this scope result = “Yes”; ^~~ Main.cc:42:21: error: ‘No’ was not declared in this scope result = “No”; ^~
这个错误提示可能是因为你的代码中包含了一些非法字符。你可以尝试重新编写代码,并确保没有使用任何不必要的特殊字符或空格。此外,在 C++ 中,字符串必须使用双引号(")而不是单引号(')来表示。下面是一个示例代码,展示如何正确地声明和初始化字符串变量:
```
#include <iostream>
#include <string>
using namespace std;
int main() {
string result = "Yes";
cout << result << endl;
result = "No";
cout << result << endl;
return 0;
}
```
这个程序将输出:
```
Yes
No
```
Main.cc:37:17: error: stray ‘\342’ in program result =“Yes”; ^ Main.cc:37:18: error: stray ‘\200’ in program result =“Yes”; ^ Main.cc:37:19: error: stray ‘\234’ in program result =“Yes”; ^ Main.cc:37:23: error: stray ‘\342’ in program result =“Yes”; ^ Main.cc:37:24: error: stray ‘\200’ in program result =“Yes”; ^ Main.cc:37:25: error: stray ‘\235’ in program result =“Yes”; ^ Main.cc:39:17: error: stray ‘\342’ in program result =“No”; ^ Main.cc:39:18: error: stray ‘\200’ in program result =“No”; ^ Main.cc:39:19: error: stray ‘\234’ in program result =“No”; ^ Main.cc:39:22: error: stray ‘\342’ in program result =“No”; ^ Main.cc:39:23: error: stray ‘\200’ in program result =“No”; ^ Main.cc:39:24: error: stray ‘\235’ in program result =“No”; ^ Main.cc: In function ‘std::__cxx11::string solution(std::__cxx11::string, std::__cxx11::string)’: Main.cc:17:20: error: ‘strlen’ was not declared in this scope int tStrLenW = strlen(words); ^~~~~~ Main.cc:17:20: note: suggested alternative: ‘mbrlen’ int tStrLenW = strlen(words); ^~~~~~ mbrlen Main.cc:27:13: error: ‘strcat’ was not declared in this scope strcat(pCharText, &msg[tMsgFlag]); ^~~~~~ Main.cc:27:13: note: suggested alternative: ‘struct’ strcat(pCharText, &msg[tMsgFlag]); ^~~~~~ struct Main.cc:36:33: error: cannot convert ‘std::__cxx11::string {aka std::__cxx11::basic_string}’ to ‘const char*’ for argument ‘2’ to ‘int strcasecmp(const char*, const char*)’ if(strcasecmp(pCharText, msg) == 0) ^ Main.cc:37:20: error: ‘Yes’ was not declared in this scope result =“Yes”; ^~~ Main.cc:39:20: error: ‘No’ was not declared in this scope result =“No”; ^
这个错误信息提示了一些编译错误。首先,代码中使用了非ASCII字符(如““”和“””),这会导致编译器无法识别。应该使用双引号(")来表示字符串。其次,代码中使用了一些未定义的函数和变量,如`strlen`、`strcat`和`strcasecmp`函数,以及`pCharText`和`result`变量。应该添加相应的头文件,如`<cstring>`头文件中包含`strlen`和`strcat`函数,`<strings.h>`头文件中包含`strcasecmp`函数。同时,需要定义和初始化`pCharText`和`result`变量。最后,应该将比较字符串的函数修改为`std::string`类型的比较,而不是使用`strcasecmp`函数。修改后的代码如下:
```
#include <iostream>
#include <cstring>
#include <string>
std::string solution(std::string words, std::string msg){
std::string result;
int tStrLenW = words.length();
int tStrLenM = msg.length();
int tWordsFlag = 0;
int tMsgFlag = 0;
char* pCharText = new char[tStrLenM+1];
memset(pCharText, 0, tStrLenM+1);
while(tStrLenW > tWordsFlag && tStrLenM > tMsgFlag)
{
if(words[tWordsFlag] == msg[tMsgFlag])
{
pCharText[tMsgFlag] = msg[tMsgFlag];
tMsgFlag++;
}
else
{
tWordsFlag++;
tMsgFlag = 0;
}
}
if(pCharText == msg)
result = "Yes";
else
result = "No";
delete[] pCharText;
return result;
}
int main() {
std::string words;
std::string msg;
getline(std::cin, words);
getline(std::cin, msg);
std::string result = solution(words, msg);
std::cout<<result<<std::endl;
return 0;
}
```
注意,这里我将比较字符串的方法修改为了`pCharText == msg`,因为在C++中,可以直接使用`==`运算符来比较两个`std::string`类型的字符串是否相等。
阅读全文