Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
My C++ console keeps returning the same value as the last.
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="omatamix" data-source="post: 472855" data-attributes="member: 84722"><p>[CODE=cpp]#ifdef _WIN32</p><p>#include <Windows.h></p><p>#else</p><p>#include <unistd.h></p><p>#endif</p><p>#include <sstream></p><p>#include <iostream></p><p>#include <array></p><p>#include <vector></p><p>#include <map></p><p></p><p>int main()</p><p>{</p><p> std::string ttoken;</p><p> std::string index;</p><p> std::string token;</p><p> std::string dataEn1;</p><p> std::string dataEn2;</p><p> std::string dataEn3;</p><p> std::string dataEn4;</p><p> int count = 0;</p><p> std::string scoreDt = "";</p><p> std::string delimiter = ";;";</p><p> std::string line = "";</p><p> while (std::getline(std::cin, line)) {</p><p> size_t pos = 0;</p><p> while ((pos = line.find(delimiter)) != std::string::npos) {</p><p> ttoken = line.substr(0, pos);</p><p> // std::cout << ttoken << std::endl;</p><p> if (count == 0) {</p><p> index = ttoken;</p><p> } else if (count == 1) {</p><p> token = ttoken;</p><p> } else if (count == 2) {</p><p> scoreDt = ttoken;</p><p> } else if (count == 3) {</p><p> dataEn1 = ttoken;</p><p> } else if (count == 4) {</p><p> dataEn2 = ttoken;</p><p> } else if (count == 5) {</p><p> dataEn3 = ttoken;</p><p> } else {</p><p> dataEn4 = ttoken;</p><p> }</p><p> line.erase(0, pos + delimiter.length());</p><p> count++;</p><p> }</p><p> if (index == "ready") {</p><p> std::cout << "ok" << std::endl;</p><p> }</p><p> if (index == "search") {</p><p> //.</p><p> }</p><p> if (index == "quit") {</p><p> break;</p><p> }</p><p> }</p><p> return 0;</p><p>}</p><p>[/CODE]</p><p></p><p>I am still learning C++, so don't judge xD.</p><p></p><p>The program returns what sould be returned when I call each command, It's when i call a scond command it keeps outputting the same value as the first command. So if i do [ICODE]ready;;[/ICODE] it returns [ICODE]ok[/ICODE] as it should and then if i do [ICODE]quit;;[/ICODE] it returns ok which it should not. But if i restart the console and do the quit command first it stops the program as it should.</p><p></p><p>I just updated the code above so It would be easier to see what is wrong.</p><p></p><p>You can compile this yourself now and you will see the problem I am having.</p></blockquote><p></p>
[QUOTE="omatamix, post: 472855, member: 84722"] [CODE=cpp]#ifdef _WIN32 #include <Windows.h> #else #include <unistd.h> #endif #include <sstream> #include <iostream> #include <array> #include <vector> #include <map> int main() { std::string ttoken; std::string index; std::string token; std::string dataEn1; std::string dataEn2; std::string dataEn3; std::string dataEn4; int count = 0; std::string scoreDt = ""; std::string delimiter = ";;"; std::string line = ""; while (std::getline(std::cin, line)) { size_t pos = 0; while ((pos = line.find(delimiter)) != std::string::npos) { ttoken = line.substr(0, pos); // std::cout << ttoken << std::endl; if (count == 0) { index = ttoken; } else if (count == 1) { token = ttoken; } else if (count == 2) { scoreDt = ttoken; } else if (count == 3) { dataEn1 = ttoken; } else if (count == 4) { dataEn2 = ttoken; } else if (count == 5) { dataEn3 = ttoken; } else { dataEn4 = ttoken; } line.erase(0, pos + delimiter.length()); count++; } if (index == "ready") { std::cout << "ok" << std::endl; } if (index == "search") { //. } if (index == "quit") { break; } } return 0; } [/CODE] I am still learning C++, so don't judge xD. The program returns what sould be returned when I call each command, It's when i call a scond command it keeps outputting the same value as the first command. So if i do [ICODE]ready;;[/ICODE] it returns [ICODE]ok[/ICODE] as it should and then if i do [ICODE]quit;;[/ICODE] it returns ok which it should not. But if i restart the console and do the quit command first it stops the program as it should. I just updated the code above so It would be easier to see what is wrong. You can compile this yourself now and you will see the problem I am having. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
My C++ console keeps returning the same value as the last.
Top