• <bdo id='kDsPo'></bdo><ul id='kDsPo'></ul>
  • <tfoot id='kDsPo'></tfoot>
      <legend id='kDsPo'><style id='kDsPo'><dir id='kDsPo'><q id='kDsPo'></q></dir></style></legend>
    1. <small id='kDsPo'></small><noframes id='kDsPo'>

      1. <i id='kDsPo'><tr id='kDsPo'><dt id='kDsPo'><q id='kDsPo'><span id='kDsPo'><b id='kDsPo'><form id='kDsPo'><ins id='kDsPo'></ins><ul id='kDsPo'></ul><sub id='kDsPo'></sub></form><legend id='kDsPo'></legend><bdo id='kDsPo'><pre id='kDsPo'><center id='kDsPo'></center></pre></bdo></b><th id='kDsPo'></th></span></q></dt></tr></i><div id='kDsPo'><tfoot id='kDsPo'></tfoot><dl id='kDsPo'><fieldset id='kDsPo'></fieldset></dl></div>

        如何在C++中放置两个反斜杠

        How to put two backslash in C++(如何在C++中放置两个反斜杠)
        <legend id='wQTPk'><style id='wQTPk'><dir id='wQTPk'><q id='wQTPk'></q></dir></style></legend>

        <small id='wQTPk'></small><noframes id='wQTPk'>

          <tbody id='wQTPk'></tbody>

        • <tfoot id='wQTPk'></tfoot>

                <bdo id='wQTPk'></bdo><ul id='wQTPk'></ul>

                <i id='wQTPk'><tr id='wQTPk'><dt id='wQTPk'><q id='wQTPk'><span id='wQTPk'><b id='wQTPk'><form id='wQTPk'><ins id='wQTPk'></ins><ul id='wQTPk'></ul><sub id='wQTPk'></sub></form><legend id='wQTPk'></legend><bdo id='wQTPk'><pre id='wQTPk'><center id='wQTPk'></center></pre></bdo></b><th id='wQTPk'></th></span></q></dt></tr></i><div id='wQTPk'><tfoot id='wQTPk'></tfoot><dl id='wQTPk'><fieldset id='wQTPk'></fieldset></dl></div>
                  本文介绍了如何在C++中放置两个反斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要创建一个接受目录路径的函数.但是为了让编译器读取反斜杠,我需要创建一个函数,将一个反斜杠变成 2 个反斜杠..到目前为止这是我的代码:

                  i need to create a function that will accept a directory path. But in order for the compiler to read backslash in i need to create a function that will make a one backslash into 2 backslash.. so far this are my codes:

                  string stripPath(string path)
                  {       
                          char newpath[99999];
                          //char *pathlong;
                          char temp;
                          strcpy_s(newpath, path.c_str());
                          //pathlong = newpath;
                          int arrlength = sizeof(newpath);
                  
                              for (int i = 0; i <= arrlength ;i++)
                              {
                                  if(newpath[i] == '\')
                                  {
                                      newpath[i] +=  '\';
                                      i++;
                                  }
                              }
                              path = newpath;
                          return path;
                  } 
                  

                  此代码接收来自用户的输入,该输入是带有单个反斜杠的目录路径.问题是它给出了一个脏文本输出;

                  this code receives an input from a user which is a directory path with single backslash. the problem is it gives a dirty text output;

                  推荐答案

                  在这一行:

                  if(newpath[i] = '\')
                  

                  = 替换为 ==.

                  在这一行:

                  newpath[i] +=  '\';
                  

                  这应该是将 添加到字符串中(我认为这就是您想要的),但它实际上对当前字符进行了一些时髦的 char 数学运算.因此,您不是插入字符,而是破坏了数据.

                  This is supposed to add a into the string (I think that's what you want), but it actually does some funky char math on the current character. So instead of inserting a character, you are corrupting the data.

                  试试这个:

                   #include <iostream>
                   #include <string>
                   #include <sstream>
                  
                  int main(int argc, char ** argv) {
                    std::string a("hello\ world");
                    std::stringstream ss;
                  
                    for (int i = 0; i < a.length(); ++i) {
                       if (a[i] == '\') {
                         ss << "\\";
                       }
                       else {
                         ss << a[i];
                       }
                    }
                  
                    std::cout << ss.str() << std::endl;
                    return 0;
                  }
                  

                  这篇关于如何在C++中放置两个反斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is Type(::x); valid?(是类型(::x);有效的?)
                  Difference between an inline function and static inline function(内联函数和静态内联函数的区别)
                  Compilation fails randomly: quot;cannot open program databasequot;(编译随机失败:“无法打开程序数据库)
                  Too many initializers error for a simple array in bcc32(bcc32 中的简单数组的初始值设定项过多错误)
                  No Member named stoi in namespace std(命名空间 std 中没有名为 stoi 的成员)
                  Error using a constexpr as a template parameter within the same class(在同一个类中使用 constexpr 作为模板参数时出错)

                  • <small id='W3G9v'></small><noframes id='W3G9v'>

                      <tbody id='W3G9v'></tbody>

                  • <legend id='W3G9v'><style id='W3G9v'><dir id='W3G9v'><q id='W3G9v'></q></dir></style></legend>
                    <tfoot id='W3G9v'></tfoot>

                    <i id='W3G9v'><tr id='W3G9v'><dt id='W3G9v'><q id='W3G9v'><span id='W3G9v'><b id='W3G9v'><form id='W3G9v'><ins id='W3G9v'></ins><ul id='W3G9v'></ul><sub id='W3G9v'></sub></form><legend id='W3G9v'></legend><bdo id='W3G9v'><pre id='W3G9v'><center id='W3G9v'></center></pre></bdo></b><th id='W3G9v'></th></span></q></dt></tr></i><div id='W3G9v'><tfoot id='W3G9v'></tfoot><dl id='W3G9v'><fieldset id='W3G9v'></fieldset></dl></div>

                        • <bdo id='W3G9v'></bdo><ul id='W3G9v'></ul>