簡體   English   中英

寫在一個向量中<string>帶 for 循環

[英]write in a vector<string> with for loop

我想做這樣的事情,但是沒有 push_back 怎么辦? current_state, next_states, 每行輸出有不同的值

std::vector<string> example;

for(i=0; i<7; i++)
{
  std::string current_state = "a";
  std::string next_states = "abcd";
  std::string outputs = "10x1";
  example.push_back("STATE \s", current_state, " TO \s", next_states, " OUT ", outputs, " \n ");
}

我試圖有這個輸出

STATE a TO abcd OUT 10x1
STATE b TO aabd OUT 11x1
STATE c TO aaac OUT 1001

您可以使用普通+運算符連接std::string對象,例如

example.push_back("STATE " + current_state + " TO " + next_states + " OUT " + outputs + " \n ");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM