C - 如何将用户的字符串输入到向量字符串中,然后在此基础上执行一些操作?

新手上路,请多包涵

我该如何进行这项工作?

 char stringw[];                   //to hold the data user enters and then copy it to the string vector .. I didnt know any direct method
cin>>stringw;
directions.push_back(stringw);    //directions is a <string> vector

我该如何做这样的检查?

if(directions[i][j])=="N") //I am getting an error

"error: expected primary-expression before '==' token"

编辑1: 错误解决 if(directions[i][j])=="N") 应该是 if(directions[i][j]=="N") 我意外关闭了括号

现在我们如何将字符串数据添加到字符串向量中?

编辑2: 解决!

实际上使用 char stringw 是数据类型 char * 并且我正在将 char * 推入一个字符串……它不是那样的。

原文由 brainst 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 253
1 个回答
#include<iostream>
#include<vector>

int main() {
    std::vector<string> data;
    string temp;
    std::cin >> temp;
    data.push_back(temp);
}

原文由 Shravan40 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题