读取各种尺寸的字符串//字符串操纵C

Reading String of Varied Sizes // String Manipulation C++

本文关键字:字符串 操纵 读取      更新时间:2023-10-16

所以我刚刚开始学习C ,我的教授短暂地转到了地址(&)和解雇(*)操作员。我不流利C ,但是我一直在寻找零件,并使用常识来合并此代码。它无法构建,请帮助!

分配 - 编写一个程序,以各种大小的字符串读取。如果输入字符串的长度大于一个存储在矢量中。当输入字符串的长度为一个(一个字符)时,您将输出存储在向量中的字符串,该字符串具有与输入字符匹配的第一个字母。在阅读字符串"退出"时继续这样做。

#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
    string input;
    char* output;
    vector<string> name;
    while (input != "quit") {
        cin >> input;
        if (input.length == 1) {
            for (int i = 0; i < name.size; i++) {
                output = &name[i].at(0);
                if (input == output) {
                    cout << name[i];
                }
            }
        }
        else {
            name.push_back(input);
        }
    }
    //system("pause");
    return 0;
}
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
    string input;
    vector<string> name;
    cin >> input;
    while (input != "quit") {
        if (input.length() == 1) {
            for (int i = 0; i < name.size(); i++) {
                if (input[0] == name[i][0]) {
                    cout << name[i] <<endl; 
                }
            }
        }
        else {
            name.push_back(input);
        }
        cin >> input;
    }
    system("pause");
    return 0;
}