简体   繁体   English

错误:预期的 ',' 或 ';' 在“{”标记之前

[英]error: expected ‘,’ or ‘;’ before ‘{’ token

So I'm writing a code that gives me the "opposite" letter on the ASCII table in c++.因此,我正在编写一个代码,该代码在 C++ 中的 ASCII 表上为我提供了“相反”字母。 I'm running into the error我遇到了错误

main.cpp:28:29: error: expected ‘,’ or ‘;’ before ‘{’ token
string letter_swap(ref_word){

Here is what I have so far:这是我到目前为止所拥有的:

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::noskipws;


string word;
string &ref_word = word;

string letter_swap(ref_word){

  int diff;
  cin >> ref_word;
  num_word = static_cast<int>(ref_word);

  if (65 <= num_word  & num_word <= 90){
    diff = 90 - num_word + 65;
    return diff;

} else if (97 <= num_word  & num_word <= 127){
    diff = 90 - num_word + 65;
    return diff;

} else{
    return ref_word;
  }

 }

I really can't tell where I'm missing the ;我真的不知道我在哪里错过了; Any help is greatly appreciated任何帮助是极大的赞赏

You haven't specified the argument type for ref_word.您尚未为 ref_word 指定参数类型。

string letter_swap(string& ref_word){

These look like they shouldn't be there:这些看起来不应该在那里:

string word;
string &ref_word = word;

You might also want to use && instead of &.您可能还想使用 && 而不是 &。

 if (65 <= num_word && num_word <= 90)

You have not declared num_word as a variable, and you can't convert a numerical text value into a numeric value like this:您尚未将 num_word 声明为变量,并且您无法将数字文本值转换为这样的数字值:

  num_word = static_cast<int>(ref_word);

You probably want to be doing something along these lines:您可能希望按照以下方式做一些事情:

  size_t sz;
  int num_word = std::stoi(ref_word, &sz);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM