# Infinite Loop or Error "system" is ambiguous

Page 1 of 1

## 11 Replies - 12147 Views - Last Post: 25 October 2013 - 06:54 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=331858&amp;s=f3edd7ecf369993da077fffd3078705b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Smokey&Ben

Reputation: 0
• Posts: 18
• Joined: 15-September 13

# Infinite Loop or Error "system" is ambiguous

Posted 18 October 2013 - 11:21 AM

Error says "system" is ambiguous
It looks like an infinite loop issue
How do I fix it?
```//abbb.cpp
#include <iostream>
using namespace std;
int main()
{
int A,B;
for (A=1;A=1;A=1)
{
cout<<"A"<<A<<endl;
//}
for (B=1;B=1;B=1)
//{
cout<<"B"<<B<<endl;
//}
for (B=2;B=2;B=2)
//{
cout<<"B"<<B<<endl;
//}
for (B=3;B=3;B=3)
//{
cout<<"B"<<B<<endl;
//}
for (A=2;A=2;A=2)
//{
cout<<"A"<<A<<endl;
//}
for (B=1;B=1;B=1)
//{
cout<<"B"<<B<<endl;
//}
for (B=2;B=2;B=2)
//{
cout<<"B"<<B<<endl;
//}
for (B=3;B=3;B=3)
//{
cout<<"B"<<B<<endl;
}
system ("Pause");
return 0;
}

```

Is This A Good Question/Topic? 0

## Replies To: Infinite Loop or Error "system" is ambiguous

### #2 jimblumberg

Reputation: 4894
• Posts: 15,286
• Joined: 25-December 09

## Re: Infinite Loop or Error "system" is ambiguous

Posted 19 October 2013 - 06:38 AM

Quote

Error says "system" is ambiguous
It looks like an infinite loop issue
How do I fix it?

Nope, not an infinite loop issue.

There are two ways of fixing your problem with system().

First don't use system() to pause the program. This system() call is very inefficient and not supported by most operating systems. Instead use cin.get() to pause the output.

Second include the proper #include file that prototypes this function. You can use the search engine of your choice to find the documentation for this function, which should tell you what include file is required.

Jim

This post has been edited by jimblumberg: 19 October 2013 - 06:39 AM

### #3 axel1994

Reputation: 86
• Posts: 169
• Joined: 27-May 13

## Re: Infinite Loop or Error "system" is ambiguous

Posted 19 October 2013 - 09:27 AM

jimblumberg, on 19 October 2013 - 01:38 PM, said:

Quote

Error says "system" is ambiguous
It looks like an infinite loop issue
How do I fix it?

Nope, not an infinite loop issue.

There are two ways of fixing your problem with system().

First don't use system() to pause the program. This system() call is very inefficient and not supported by most operating systems. Instead use cin.get() to pause the output.

Second include the proper #include file that prototypes this function. You can use the search engine of your choice to find the documentation for this function, which should tell you what include file is required.

Jim

But:
```for (A=1;A=1;A=1)
```

will give an infinite loop.
At least it does in Visual Studio 2012.

A is initialised to 1.
A gets set to 1. 1 evaluates to true.
A gets set to 1.
A gets set to 1. 1 evaluates to true.
And so on.

(If I'm correct on what happens)

This post has been edited by axel1994: 19 October 2013 - 09:28 AM

### #4 salazar

Reputation: 105
• Posts: 641
• Joined: 26-June 13

## Re: Infinite Loop or Error "system" is ambiguous

Posted 19 October 2013 - 10:05 AM

Yeah, that is an infinite loop. You should never assign in the conditional section of for loops. You should study some for loops that are written properly.

This post has been edited by salazar: 19 October 2013 - 10:06 AM

### #5 jimblumberg

Reputation: 4894
• Posts: 15,286
• Joined: 25-December 09

## Re: Infinite Loop or Error "system" is ambiguous

Posted 19 October 2013 - 04:58 PM

Quote

will give an infinite loop.

Yes there is an infinite loop. But the OP didn't ask about that, he asked about an error about his system() call, the infinite loop is not the cause of the error that was reported.

Also if the OP used a decent compiler he would get more warning/error messages than what was shown.

Quote

main.cpp||In function ‘int main()’:|
main.cpp|7|warning: suggest parentheses around assignment used as truth value [-Wparentheses]|
main.cpp|11|warning: suggest parentheses around assignment used as truth value [-Wparentheses]|
main.cpp|15|warning: suggest parentheses around assignment used as truth value [-Wparentheses]|
main.cpp|19|warning: suggest parentheses around assignment used as truth value [-Wparentheses]|
main.cpp|23|warning: suggest parentheses around assignment used as truth value [-Wparentheses]|
main.cpp|27|warning: suggest parentheses around assignment used as truth value [-Wparentheses]|
main.cpp|31|warning: suggest parentheses around assignment used as truth value [-Wparentheses]|
main.cpp|35|warning: suggest parentheses around assignment used as truth value [-Wparentheses]|

I didn't comment about the rest of the code because that was not the reported problem.

Jim

### #6 Smokey&Ben

Reputation: 0
• Posts: 18
• Joined: 15-September 13

## Re: Infinite Loop or Error "system" is ambiguous

Posted 20 October 2013 - 06:24 PM

Okay first to clarify I use Visual Studio 2010.
-as long it runs correctly it is fine is my philosophy
Second system("Pause")is very efficient and is supported by all of my operating systems
Third I am a student and my professor forbids use getline
-cin.get() I'm not familiar with it at all

I want it to print using nested loops A1B1B2B3A2B1B2B3

### #7 jimblumberg

Reputation: 4894
• Posts: 15,286
• Joined: 25-December 09

## Re: Infinite Loop or Error "system" is ambiguous

Posted 20 October 2013 - 07:30 PM

Quote

Second system("Pause")is very efficient and is supported by all of my operating systems

No, it's not efficient and relying on system specific functionality when learning a language is also very inefficient. But since you think the only valid operating system is Windows, I'll let someone else address most of your other issues.

Quote

Okay first to clarify I use Visual Studio 2010.
-as long it runs correctly it is fine is my philosophy

Since it's not running correctly what do you think you should do?

Quote

Third I am a student and my professor forbids use getline
-cin.get() I'm not familiar with it at all

Then what exactly do you use to get input from the user?

Good luck with your attitude you're really going to need it.

Jim

### #8 Smokey&Ben

Reputation: 0
• Posts: 18
• Joined: 15-September 13

## Re: Infinite Loop or Error "system" is ambiguous

Posted 21 October 2013 - 10:10 AM

Okay their other systems than windows but I use Windows and in some cases system("Pause") may not be efficient.
I use cin>> for my programs except with in some cases with strings.
When my program does not run correctly I turn to my peer my student advisors my professor and in some cases my fellow respectable programmers.
I try to help them when I can to in exchange.

### #9 Smokey&Ben

Reputation: 0
• Posts: 18
• Joined: 15-September 13

## Re: Infinite Loop or Error "system" is ambiguous

Posted 21 October 2013 - 10:18 AM

Here is the complete code
```//abbb.cpp
#include <iostream>
using namespace std;
int main()
{
int A,B;
for(A=1;A<2;A++)
{
cout<<"A"<<A;
}
for(B=1;B<=3;B++)
{
cout<<"B"<<B;
}
for(A=2;A<3;A++)
{
cout<<"A"<<A;
}

for(B=1;B<=3;B++)
{
cout<<"B"<<B;
}
system ("Pause");
return 0;
}

```

### #10 Skydiver

• Code herder

Reputation: 4784
• Posts: 15,811
• Joined: 05-May 12

## Re: Infinite Loop or Error "system" is ambiguous

Posted 21 October 2013 - 09:27 PM

If you are using Visual Studio, there is no need for the system() call. Simply press Ctrl-F5. It will hold the console window open for you.

### #11 Smokey&Ben

Reputation: 0
• Posts: 18
• Joined: 15-September 13

## Re: Infinite Loop or Error "system" is ambiguous

Posted 24 October 2013 - 07:42 PM

Thanks Skydiver

### #12 ccubed

• It's That Guy

Reputation: 164
• Posts: 1,416
• Joined: 13-June 08

## Re: Infinite Loop or Error "system" is ambiguous

Posted 25 October 2013 - 06:54 AM

In case you want to know for future assignments, system is defined in cstdlib. So
```#include <cstdlib> //contains system

```

Smokey&Ben, on 20 October 2013 - 07:24 PM, said:

Okay first to clarify I use Visual Studio 2010.
-as long it runs correctly it is fine is my philosophy

```void makeNumber(int *num);
int main(){
int *a=NULL;
makeNumber(a);
}
void makeNumber(int *num){
num = new int;
}

```

This code runs fine, but it's certainly not 'ok.' It creates a memory leak. Never assume that compiling and running is the same as working.

Smokey&Ben, on 20 October 2013 - 07:24 PM, said:

Second system("Pause")is very efficient and is supported by all of my operating systems

System("Pause") is not efficient in any way. There hasn't really ever been an argument on this point. It's also not a guarantee that it will work. It's the same as typing pause into the command prompt. You're assuming that there is a program in the user's path that is named pause and hoping that there isn't a pause in the current folder. Because if there is, it doesn't work. Windows, for all its bad, does at least one thing correct: It resolves requests locally and moving up rather than starting at the top and moving down.

IT's also a shortcut that doesn't actually teach you programming.

Smokey&Ben, on 20 October 2013 - 07:24 PM, said:

Third I am a student and my professor forbids use getline
-cin.get() I'm not familiar with it at all

cin.get is not getline. Getline is a c++ function that copies a line from a stream up to a \n into a string.
cin.get is a function with several uses which you can read here.

This post has been edited by ccubed: 25 October 2013 - 07:09 AM

Page 1 of 1

 .related ul{list-style-type:circle;font-size:12px;font-weight:bold;}.related li{margin-bottom:5px;background-position:left 7px!important;margin-left:-35px;}.related h2{font-size:18px;font-weight:bold;}.related a{color:blue;}