【发布时间】:2021-09-25 22:12:56
【问题描述】:
我正在编写一个函数,应该输出字符串中大括号之间的任何内容
(例如,hello world 代表 text{hello world})。
但是当我尝试运行它时它没有输出任何东西。您知道可能出了什么问题吗?
#include <iostream>
#include <string>
using namespace std;
int main(){
start:
std::string funct;
std::cout << "-->";
std::cin >> funct;
int temp = 0;
//focus on what's down here V
string word;
if (funct.find("text") != string::npos)
{
for(int i=0; i<1; i){
if(funct.at(temp)=='}'){i=1;}
else{
temp += temp;
word = funct.at(temp + 5);}
}
cout<<word<<endl;
}
cout<<endl<<endl<<"=================================================="<<endl<<endl;
goto start;
return 0;
}
*Edit,'funct' 是原始用户输入,'temp' 只是一个占位符整数。
【问题讨论】:
-
请发minimal reproducible example(即分享一个程序而不是sn-p)。
-
什么是函数? temp 已定义。
-
@Jorengarenar。 OP 想要创建一个函数,该函数接受一个看起来像
text{...}的输入,并且函数应该返回大括号内的所有内容 -
@smac89 哦,更有意义。
-
尝试
cout << word << endl;而不是cout << endl << word;