2015-06-14 181 views
-1

我試圖在數組中輸入兩個`backqoutes。但它輸入單引號。你能幫我在這裏嗎?替換字符串中的字符

輸入:

abc"cde"fgh"ijkl" 

輸出繼電器:

abc``cde''fgh``ijkl'' 

我的代碼:

#include <stdio.h> 
#include <iostream> 
#include <cstring> 

using namespace std; 

int main() 
{ 
    string mystr; 
    long int i=0,j=0,l; 
    while(getline (cin, mystr)) 
    { 
     // l=strlen(mystr); 
     l=mystr.length(); 
     for(i=0;i<l;i++) 
     { 
      if (mystr[i]=='"') 
      { 
       j=j+1; 
       if(j%2==1) 
        mystr[i]='``'; //Problem is here 
       else 
        mystr[i]='"'; 
      } 
     } 
     cout << mystr; 
     i++; 
    } 
    return 0; 
} 
+0

Srry for my bad mistake – jisan

回答

1

這是C++。但是「``」不是一個字符,而是2個字符。使用連接而不是像

Result += "``";