Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Constexpr错误_C++_Templates - Fatal编程技术网

C++ Constexpr错误

C++ Constexpr错误,c++,templates,C++,Templates,好的,我修正了错误。谢谢你们。但现在,当我运行它时,我在菜单中选择了D,但只有“您选择分割文字并删除段落中的重复项”&“就是这样”打印出来。在那之后就什么也看不出来了。。。有人知道会是什么吗?提前谢谢你 应该是这样的: 当选择第四个选项(“拆分单词”)时,单词应放入数组或结构中,并且每个单词都应显示一个循环。在此之后,应执行重复删除,程序必须确定重复字并消除它们。在此之后,应再次打印单词列表 #include <iostream> #include <cmath> #in

好的,我修正了错误。谢谢你们。但现在,当我运行它时,我在菜单中选择了D,但只有“您选择分割文字并删除段落中的重复项”&“就是这样”打印出来。在那之后就什么也看不出来了。。。有人知道会是什么吗?提前谢谢你

应该是这样的:

当选择第四个选项(“拆分单词”)时,单词应放入数组或结构中,并且每个单词都应显示一个循环。在此之后,应执行重复删除,程序必须确定重复字并消除它们。在此之后,应再次打印单词列表

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <cctype>
#include <sstream>
#include <set>

using namespace std;
int main()
{

    string s;
    char selection;
    string w;
    string buf;


    cout << "Enter a paragraph or a sentence : " ;

    getline(cin, s);

    int sizeOfString = s.length(); 

    //cout << "The paragraph has " << sizeOfString << " characters. " << endl; ***Dummy call to see if size works. 

    //cout << "You entered " << s << endl; *** Dummy function !!

    cout << "" << endl;

    cout << "                 Menu          " << endl;
    cout <<"        ------------------------" << endl;
    cout << "" << endl;
    cout << "A -- Convert paragraph to all caps " << endl;
    cout << "B -- Convert paragraph to all lowercase " << endl;
    cout << "C -- Delete whitespaces " << endl;
    cout << "D -- Split words & remove duplicates " << endl;
    cout << "E -- Search a certain word " << endl;
    cout << "" << endl;
    cout << "Please select one of the above: " ;
    cin >> selection;
    cout << "" << endl;

    stringstream ss(s); 
    set<string> tokens;

    switch (selection) //Switch statement
    {
        case 'a':
        case 'A': cout << "You chose to convert the paragraph to all uppercase" << endl;
                  cout << "" << endl;
                  for(int i=0; s[i]!='\0'; i++)
                    {
                        s[i]=toupper(s[i]);
                    }
                    cout << "This is it: " << s << endl;
                  break;
        case 'b':
        case 'B': cout << "You chose to convert the paragragh to all lowercase" << endl;
                  cout << "" << endl;
                  for (int i=0; s[i] !='\0'; i++)
                  {
                      s[i]=tolower(s[i]);
                  }
                    cout << "This is it: " << s << endl;
                    break;
        case 'c':
        case 'C': cout << "You chose to delete the whitespaces in the paragraph" << endl;
                  cout << "" << endl;
                  for(int i=0; i<s.length(); i++)
                    if(s[i] == ' ') s.erase(i,1);
                  cout <<"This is it: " << s << endl;
                  break;
        case 'd':
        case 'D': cout << "You chose to split the words & remove the duplicates in the paragraph" << endl;
                  cout << "" << endl;

                 // Insert the string into a stream

                  // Create vector to hold our words

                  while (ss >> buf)
                    tokens.insert(buf);

                  cout << "This is it: " << endl;

                  for (set<string>::iterator it = tokens.begin(); it != tokens.end(); ++it)
                    {
                        cout << *it << " ";
                    }

        cout << endl;

        break;




        case 'e':
        case 'E': cout << "You chose to search for a certain word in the paragraph. " << endl;
                  cout << "" << endl;
                  cout << "Enter the word you want to search for: ";
                  cin >> w;

                  s.find(w);
                  if ( s.find( w ) != std::string::npos )
                  {
                      cout << w << " was found in the paragraph. " << endl;

                  }
                 else 
                  {
                    cout << w << " was not found in the paragraph. " << endl;
                  }




    }


    return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
int main()
{
字符串s;
字符选择;
字符串w;
字符串buf;
cout1)


使用空字符串创建String String,这会导致流为空。在实际读取字符串后,考虑创建String String对象。String String不包含对字符串对象的引用,因此对字符串流的任何修改都基于该流,不反映流中的这些更改。D,在for循环中,你有

set
s
不是一种类型。我想你是想写字符串。欢迎来到Stack Overflow!添加一个更具描述性的标题会让这篇文章更受关注。另外,我会尽量减少你作为示例发布的代码。
set::iterator
应该是
set::iterator
什么编译器你在使用吗?它没有告诉你在哪一行出现了错误吗?我认为很多错误都是由于Luke和Nathan所说的,但是如果你指出它们在哪里就好了。现在我们看不到“ss”以前是如何定义和使用的。请在“编辑:”之后在原始帖子的末尾添加后续问题。然后做一个很好的总结对其进行格式化,可以让人们更容易地帮助您。我不喜欢这些括号…它们看起来很悲伤。在一个案例中声明的局部变量在下面仍然可见。但是初始化被切换到下面的案例跳过。
set<s>::iterator 
set<string>::iterator
case 'D':{

}
break;

case 'e':

case 'E':{


}
break;