Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.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++ 如何在C+中创建一系列三叉图+;下面的三元图从第一个字母的第二个字母开始?_C++_N Gram_Trigram - Fatal编程技术网

C++ 如何在C+中创建一系列三叉图+;下面的三元图从第一个字母的第二个字母开始?

C++ 如何在C+中创建一系列三叉图+;下面的三元图从第一个字母的第二个字母开始?,c++,n-gram,trigram,C++,N Gram,Trigram,我已经在这方面工作了一段时间,但我还没能解决这个问题。本质上,如果给用户一个“.txt”文件,其中写入了以下内容,”tHe@doG#上了$tHE!hiLL!,最终结果需要如下所示: the hed edo dog ogw gwe wen ent ntu ... 我可以继续,但我相信这是不言自明的。下面显示了我用来尝试和实现这一点的代码 #include "functions.h" #include "bigint/bigint.h" #include <ctype.h> #incl

我已经在这方面工作了一段时间,但我还没能解决这个问题。本质上,如果给用户一个“.txt”文件,其中写入了以下内容,
”tHe@doG#上了$tHE!hiLL!
,最终结果需要如下所示:

the
hed
edo
dog
ogw
gwe
wen
ent
ntu
...
我可以继续,但我相信这是不言自明的。下面显示了我用来尝试和实现这一点的代码

#include "functions.h"
#include "bigint/bigint.h"
#include <ctype.h>
#include <string>
#include <cstdio>
#include <stdio.h>


int main(int argc, char *argv[]) {

std::vector<std::string> v(17575);
std::string tri1;
std::string tri2;
std::string tri3;

for (int i = 1; i < argc; i++) {

    char* filename = argv[i];
    std::ifstream infile;

    infile.open(filename);

    // executes for discoverable files  
    if(! infile.fail()) {

        char ch;

        while (infile.get(ch)) {

            if (isspace(ch) || ispunct(ch) || isdigit(ch)) {
                continue;
            }

            else if (isupper(ch)) {
                ch = tolower(ch);
            }

            tri1 += ch;

            char ch2 = infile.peek();

            if (isspace(ch2) || ispunct(ch2) || isdigit(ch2)) {
                ch2 = infile.peek() + 1;
            }

            else if (isupper(ch2)) {
                ch2 = islower(ch2);
            }

            tri2 += ch2;

            char ch3 = infile.peek() + 1;

            if (isspace(ch3) || ispunct(ch3) || isdigit(ch3)) {
                ch3 = infile.peek() + 2;
            }

            else if (isupper(ch3)) {
                ch3 = islower(ch3);
            }

            tri3 += ch3;

            if (tri1.length() == 3) {
                std::cout << tri1 << std::endl;                 
                v.push_back(tri1);
                tri1 = "";
            }

            if (tri2.length() == 3) {
                std::cout << tri2 << std::endl;                 
                v.push_back(tri2);
                tri2 = "";
            }

            if (tri3.length() == 3) {
                std::cout << tri3 << std::endl;                 
                v.push_back(tri3);
                tri3 = "";
            }

        } //while


        infile.close();
    }

    // executes for non-discoverable files
    else {
        std::cerr << "Unable to open file: " << filename << '\n';
    }
}

return 0;
#包括“functions.h”
#包括“bigint/bigint.h”
#包括
#包括
#包括
#包括
int main(int argc,char*argv[]){
标准:向量v(17575);
std::字符串tri1;
std::字符串tri2;
std::字符串tri3;
对于(int i=1;istd::那么,代码有效吗?你的问题不清楚。如果你的代码有问题,你需要详细说明问题。如果它工作正常,你可能正在寻找代码审查SE。你似乎忽略了数字,你应该在输入中提到这是一个家庭作业,还是来自某个愚蠢的在线测验网站的愚蠢问题?或者这样,正确解决方案的主要部分应该是一个简单的循环,可能由4-5行代码组成。不需要三个
std::string
s。不需要一堆
if
语句。如果您的代码不是一个
char[4]
array,一个循环,一个
int
变量,还有两个
if
语句,你的家庭作业或在线测验都会失败。我的代码不起作用,我也不确定如何修复它。你试过了吗?你的橡皮鸭给了你什么建议?我从来不知道这个调试过程有名字很不幸,我现在只使用C++,所以我的橡皮鸭子最初认为if语句的集合应该工作,不是很有效,但是仍然有效。